Firefox中 空白字符,好比回车,空格等也算做一个Nodenode
就是firstChild,nextsbiling这两个.
下面给出函数吧.仍是代码比较说明问题
代码都是网上来的.
不过要注意的是,getNext和getFirstChild是不同的
next是下一个,同级别的下一个,不会取到本身这个节点的子节点.dom
多是由于对dom的理解不同ie和firefox对firstChild,nextSbiling的处理不太同样.
因此要取到下一个结点,只能用type来判断了.函数
function getNextSibling(startBrother){
endBrother=startBrother.nextSibling;
while(endBrother.nodeType!=1){
endBrother = endBrother.nextSibling;
}
return endBrother;
}firefox
function getNextSibling1(obj){
if(obj.nextSibling.nodeType==3) {
sibling=obj.nextSibling.nextSibling; // Moz. Opera
}
else {
sibling=obj.nextSibling; // IE
}
return sibling;
}
function getFirstChild(obj){
for (i=0; i<obj.childNodes.length; i++){
if (obj.childNodes[i].nodeType==1)
return obj.childNodes[i];
else
continue;
}get