The examples in this article describe three implementation methods of generating img tags with javascript. Share it with everyone for your reference, the details are as follows:
<div id="d1"></div> <script> //HTML function a(){ document.getElementById("d1").innerHTML="<img src='http://baike.baidu.com/cms/rc/240x112dierzhou.jpg'>"; } a(); //方法 function b(){ var d1=document.getElementById("d1"); var img=document.createElement("img"); img.src="http://baike.baidu.com/cms/rc/240x112dierzhou.jpg"; d1.appendChild(img); } b(); //对象 function c(){ var cc=new Image(); cc.src="http://baike.baidu.com/cms/rc/240x112dierzhou.jpg"; document.getElementById("d1").appendChild(cc); } c(); </script>
I hope this article will be helpful to everyone in JavaScript programming.