

一、在一个p前添加p
<html>
<body>
<p id="a">
<p id="a1">1</p>
<p id="a2">2</p>
</p>
<a href="javascript:addp();">test</a>
</body>
<script type="text/javascript">
function addp(){
var newNode=document.createElement("p");
newNode.setAttribute("id","a3");
var txtNode=document.createTextNode("3");
newNode.appendChild(txtNode);
document.getElementById("a").insertBefore(newNode,document.getElementById("a2"));
alert(document.getElementById("a").innerHTML)
}
</script>
</html>更多相关教程请访问 JavaScript视频教程
