简体   繁体   中英

To display image using JavaScript

In the code below I have an image in C Directory and I want to display the image on window load using JavaScript. I tried but image is not displaying.

<div id="thmbDiv"></div>

Script:

window.onload=function() {
    var thumbContainer = document.getElementById("thmbDiv");
    var thumbnail = document.createElement("img");
    thumbnail.onload=function() {
        thumbContainer.appendChild(thumbnail);
    }
    thumbnail.src = "C:\Hello\Search\Image0529.jpg";
}

Try

<div id="thmbDiv"><img id="imageTag" src=""></div>

window.onload=function() {
 var thumbnail = document.getElementById("imageTag");
 thumbnail.src="C:\Hello\Search\Image0529.jpg";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM