Firefox中 空白字符,比如回车,空格等也算作一个Node

就是firstChild,nextsbiling这两个.
下面给出函数吧.还是代码比较说明问题
代码都是网上来的.
不过要注意的是,getNext和getFirstChild是不一样的
next是下一个,同级别的下一个,不会取到自己这个节点的子节点.

可能是因为对dom的理解不一样ie和firefox对firstChild,nextSbiling的处理不太一样.
所以要取到下一个结点,只能用type来判断了.


function getNextSibling(startBrother){
  endBrother=startBrother.nextSibling;
  while(endBrother.nodeType!=1){
    endBrother = endBrother.nextSibling;
  }
  return endBrother;
}

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;
}

 

相关文章:

  • 2021-10-09
  • 2022-12-23
  • 2021-10-09
  • 2021-10-07
  • 2022-12-23
  • 2021-07-30
  • 2022-02-18
  • 2022-12-23
猜你喜欢
  • 2021-09-02
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
  • 2022-12-23
相关资源
相似解决方案