为什么body里面最有还有script元素
遍历body里面的元素节点,scrpt明明在body外,不算子节点,为什么出现在遍历结果中?
<body>
<div id="oDiv1">元素1</div>
<div id="oDiv2">元素2</div>
<div id="oDiv4">元素3</div>
<div id="oDiv5">元素4</div>
<div id="oDiv6">元素5</div>
<div id="oDiv7">元素6</div>
<div id="oDiv8">元素7</div>
<div id="oDiv9">元素8</div>
</body>
<script>
//这里script在body外面,但是运行和调试结果显示bodyNodeList里面最后的元素是script
var bodyNode=document.body;
if(bodyNode.hasChildNodes()){
var bodyNodeList=bodyNode.childNodes;
var bodyNodeLen=bodyNodeList.length;
//遍历body里的元素节点
for(var i=0;i<bodyNodeLen;i++){
if(bodyNodeList.item(i).nodeType==1)
getNodeInfo(bodyNodeList.item(i));
}
}
function getNodeInfo(_n){
document.write("节点名:"+_n.nodeName+"<br>");
document.write("节点值:"+_n.innerHTML+"<br>");
document.write("id属性:"+_n.id+"<br>");
document.write("============================"+"<br>");
}
</script>
<body>
.....
<script>
.....
</script>
</body>