var els=document.getElementsByTagName("body")[0].childNodes;
for(i=0;i<els.length;i++){
if(els[i].nodeType == 1 && els[i].id) alert (els[i].id);
}
其中的0是什么意思啊?是指body中的第一个元素吗?
而div就是第一个 而childNode就应该是第一个div的子节点
也就是输出两个p才对呀 但是为什么是main 和 ku 呢?
<body><div id="main">
<p class="intro">welcome to my web site</p>
<p>we sell all the widget you need </p>
</div><div id="ku">
<p class="intro">welcome to my web site</p>
<p>we sell all the widget you need </p>
</div><p class="firstp">lglg</p>
for(i=0;i<els.length;i++){
if(els[i].nodeType == 1 && els[i].id) alert (els[i].id);
}
其中的0是什么意思啊?是指body中的第一个元素吗?
而div就是第一个 而childNode就应该是第一个div的子节点
也就是输出两个p才对呀 但是为什么是main 和 ku 呢?
<body><div id="main">
<p class="intro">welcome to my web site</p>
<p>we sell all the widget you need </p>
</div><div id="ku">
<p class="intro">welcome to my web site</p>
<p>we sell all the widget you need </p>
</div><p class="firstp">lglg</p>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货