insertBefore() 方法可在已有的子节点前插入一个新的子节点

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>

<ul id="test"><li>JavaScript</li><li>HTML</li></ul>

<script type="text/javascript">

var otest = document.getElementById("test");
var newnode = document.createElement("li");
newnode.innerHTML = "PHP";
otest.insertBefore(newnode,otest.childNodes[1]);

</script>

</body>
</html>

posted on 2016-04-06 22:37  David1314  阅读(625)  评论(0编辑  收藏  举报

导航