javascript里childNodes和children的区别

<html>
<head>
<script>
function init() {
for (var j = 0; j <= document.getElementById("dots").children.length; j++) {
alert(document.getElementById("dots").childNodes[j].innerHTML);
alert(document.getElementById("dots").children[j].innerHTML);
}
}
</script>
</head>
<body onload="init()">
<div id="dots" style="width: 500px; height: 20px;"><span id="a">first</span><span id="b">second</span><span id="c">third</span><span id="d">forth</span><span id="e">fifth</span><div></div></div>
</body>
</html>

http://www.mbzhan.com/biancheng/JavaScript/11073.html

posted @ 2013-02-27 09:54  猪在飞啊  阅读(289)  评论(0编辑  收藏  举报