<div id="wrapper">
<span id="c1">hello</span>
<div id="c2">world</div>
</div>function $(i)
{
return document.getElementById(i);
}
for(var i=0;i<$("wrapper").childNodes.length;i++)
alert($("wrapper").childNodes[i].nodeName);问题是
谷歌反应 #text SPAN #text DIV #text
火狐 #text SPAN #text DIV #text
IE8 SPAN #text DIV我就纳闷了,,childNodes返回节点列表嘛,怎么去理解啊??对这个属性云里雾里了
<span id="c1">hello</span>
<div id="c2">world</div>
</div>function $(i)
{
return document.getElementById(i);
}
for(var i=0;i<$("wrapper").childNodes.length;i++)
alert($("wrapper").childNodes[i].nodeName);问题是
谷歌反应 #text SPAN #text DIV #text
火狐 #text SPAN #text DIV #text
IE8 SPAN #text DIV我就纳闷了,,childNodes返回节点列表嘛,怎么去理解啊??对这个属性云里雾里了
<div id="wrapper"><span id="c1">hello</span><div id="c2">world</div></div>不换行,就一样了,
因为火狐会把换行都认为是一个节点
最好用children替代childNodes
{
return document.getElementById(i);
}
for(var i=0;i<$("wrapper").childNodes.length;i++)
alert($("wrapper").childNodes[i].nodeName);