Home > Web Front-end > JS Tutorial > body text

Example analysis of how to use Javascript to insert pictures into Div

黄舟
Release: 2017-07-26 14:25:31
Original
11880 people have browsed it

HTML5 is popular, JS also needs to be refined

Use Javascript to insert an image into a p

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script type="text/javascript"> 
	window.onload = function (){  
		var bigImg = document.createElement("img");		//创建一个img元素
		bigImg.src="http://www.baidu.com/img/baidu_sylogo1.gif";   //给img元素的src属性赋值
		//bigImg.width="320";  //320个像素 不用加px
		var myp = document.getElementById(&#39;myp&#39;); //获得dom对象
		myp.appendChild(bigImg);  	//为dom添加子元素img
	};
</script> 
</head>
<body>
<p id="myp" style="border:1px solid #eee;width:320px;height:160px;"></p>
</body>
</html>
Copy after login

The above is the detailed content of Example analysis of how to use Javascript to insert pictures into Div. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!