如何使用Javascript往Div中插入图片的实例分析
来源:懂视网
责编:小采
时间:2020-11-27 20:15:01
如何使用Javascript往Div中插入图片的实例分析
如何使用Javascript往Div中插入图片的实例分析:HTML5火了,JS也得炼一炼用Javascript往一个p中插入一张图片<html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <script ty
导读如何使用Javascript往Div中插入图片的实例分析:HTML5火了,JS也得炼一炼用Javascript往一个p中插入一张图片<html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <script ty

HTML5火了,JS也得炼一炼
用Javascript往一个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('myp'); //获得dom对象
myp.appendChild(bigImg); //为dom添加子元素img
};
</script>
</head>
<body>
<p id="myp" style="border:1px solid #eee;width:320px;height:160px;"></p>
</body>
</html>
如何使用Javascript往Div中插入图片的实例分析
如何使用Javascript往Div中插入图片的实例分析:HTML5火了,JS也得炼一炼用Javascript往一个p中插入一张图片<html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <script ty