<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
onload = function () {
//创建img标签
var img = document.createElement('<img src="imgs/1.jpg" />;');
//获取父标签
var div = document.getElementById("dv");
//获取旧标签
var p = document.getElementById("p2");
//将创建的img标签放到第二个p标签前面
div.insertBefore(img, p);
};
</script>
</head>
<body>
<div id="dv">
<p>第一段</p>
<p id="p2">第二段</p>
<p>第三段</p>
</div>
</body>
</html>
|
|