1 回答

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊
您可以將圖像src屬性設(shè)置為從本地存儲(chǔ)獲取的值。(假設(shè)這是圖像的路徑)
您不想設(shè)置innerHTML標(biāo)簽的img。相反,使用另一個(gè)元素來顯示文本。
<div id="result"></div>
<img src="" id="photo" /> //this is the img element
<div id="msg"></div>
<script>
if (typeof(Storage) !== "undefined") {
var name = localStorage.getItem('name');
var dataImage = localStorage.getItem('imgData');
var imageName = localStorage.getItem("name");
var imageEl = document.getElementById("photo");
imageEl.src = imageName
} else {
document.getElementById("msg").innerHTML = "Sorry, your browser does not support Web Storage...";
}
</script>
添加回答
舉報(bào)