nextSibling
- javascript
- jquery
- html
- css3
- php
- java
function get_nextSibling(n){
var x=n.nextSibling;
while (x && x.nodeType!=1){
x=x.nextSibling;
}
return x;
}
var x=document.getElementsByTagName("li")[0];
document.write(x.nodeName);
document.write(" = ");
document.write(x.innerHTML);
var y=get_nextSibling(x);
if(y!=null){
document.write("
nextsibling: ");
document.write(y.nodeName);
document.write(" = ");
document.write(y.innerHTML);
}else{
document.write("
已经是最后一个节点");
}
问题1:
while 中的(x && x.nodeType!=1) 为什么这里要用上x&&x.nodeType!=1;执行顺序是啥。空白节点的type不是3吗?为什么要用上这么一段判断语句呢?直接判断x.previousSibling=3不就行了吗?为什么要用上x&&x.nodeType!=1呢?求详细点解答。谢谢了!很迷惑