标签:blog http 使用 os io ar 问题 cti
在FireFox中包含众多空格作为文本节点,因此在我们使用nextSibling和previousSibling时就会出现问题。因为FireFox会把文本节点误当做元素节点的兄弟节点来处理。我们可以添加nodeType来判断。当上一节点或者是下一节点为文本节点时,就继续寻找,直到找到下一个元素节点。以下代码仅供参考,在fireFox中测试通过:
//下一个兄弟节点 function nextSibling(node) { var tempLast = node.parentNode.lastChild; if (node == tempLast) return null; var tempObj = node.nextSibling; while (tempObj.nodeType != 1 && tempObj.nextSibling != null) { tempObj = tempObj.nextSibling; } return (tempObj.nodeType==1)? tempObj:null; } //前一个兄弟节点 function prevSibling(node) { var tempFirst = node.parentNode.firstChild; if (node == tempFirst) return null; var tempObj = node.previousSibling; while (tempObj.nodeType != 1 && tempObj.previousSibling != null) { tempObj = tempObj.previousSibling; } return (tempObj.nodeType==1)? tempObj:null; }
其中nodeType的值主要有以下几种:
nextSibling和lastSibling,布布扣,bubuko.com
标签:blog http 使用 os io ar 问题 cti
原文地址:http://www.cnblogs.com/lovefan/p/3919696.html