Home > Web Front-end > JS Tutorial > 3 implementation methods for generating img tags with javascript (object, method, html)_javascript skills

3 implementation methods for generating img tags with javascript (object, method, html)_javascript skills

WBOY
Release: 2016-05-16 15:23:31
Original
1665 people have browsed it

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>

Copy after login

I hope this article will be helpful to everyone in JavaScript programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template