袁来如此的工作笔记
袁来如此的工作笔记
竹杖芒鞋轻胜马,谁怕? 一蓑烟雨任平生。

nextSibling IE有效 FF无效

浏览量:815

 parentNode 、childNodes 、 previousSibling和nextSibling,FF和IE9中会把回车行换当作一个#TEXT节点。要把html中的空格和换行都去掉就好了,汗。

 

    function nextSib(node){

     var tempLast = node.parentNode.lastChild;

     if(node == tempLast)

      return null;

     var tempObj=node.nextSibling;

     while(tempObj.nodeType != 1 && tempObj.nextSibling != null)

      temObj = tempObj.nextSibling;

     return (tempObj.nodeType == 1)? tempObj:null;

    }

   

    function prvSib(node){

     var tempFirst = node.parentNode.firstChild;

     if(node == tempFirst)

      return null;

     var temObj= node.previousSibling;

     while(temObj.nodeType !=1 && temObj.previousSibling != null)

      temObj = temObj.previousSibling;

     return (temObj.nodeType == 1)? temObj:null;

    }


打赏