insertBefore , previousSibling
我下面代码输出不是应该是在HTML前插入php?
哪里错了?
把ot,otest.childNodes[2].previousSibling 换成ot,otest.childNodes[1].previousSibling
输出就是正确的
<!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 id="id1">HTML</li></ul>
<script type="text/javascript">
var otest = document.getElementById("test");
var ote = document.getElementById("id1");
var ot = document.createElement("li");
ot.innerHTML ="php";
otest.insertBefore(ot,otest.childNodes[2].previousSibling);
</script>
</body>
</html>