This article mainly introduces three implementation methods for generating img tags in javascript, including object, method, and html, which has some reference value, for more information about how to use javascript to generate an img tag, see the following example. We will share this with you for your reference. The details are as follows:
Script // HTMLfunction a () {document. getElementById ("d1 "). innerHTML = "";} a (); // method 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 (); // Object 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 help you design JavaScript programs.