求教~.childNodes[-1]和。childNodes[1]的問題
<body>
<ul?id="test"><li>JavaScript</li><li>HTML</li></ul>?
<script?type="text/javascript">
??var?otest?=?document.getElementById("test");??
??var?myli=document.createElement("li");
??myli.innerHTML="php";
??otest.insertBefore(myli,otest.childNodes[-1]);
??//?otest.insertBefore(myli,otest.childNodes[1]);??這樣可以,但是otest.childNodes[-1]為何不可?
</script>?
</body>
</html>
2017-02-12
我也是初學,可能和瀏覽器的兼容性有關,具體的就不知道了。
2017-02-10
document.write(otest.childNodes.length)輸出一下你就知道了