我把它改了改想要把所有的兄弟节点都找到,为什么就输不出下面调用get_previousSibling()的结果呢?如果把get_nextSibling()的调用屏蔽掉就可以了,这是为什么?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>nextSibling</title>
</head>
<body>
<ul id="u1">
<li id="a">javascript</li>
<li id="b">jquery</li>
<li id="c">html</li>
</ul>
<ul id="u2">
<li id="d">css3</li>
<li id="e">php</li>
<li id="f">java</li>
</ul>
<script type="text/javascript">
function get_nextSibling(n){
var x=n.nextSibling;
while (x && x.nodeType!=1){
x=x.nextSibling;
}
if(x.nextSibling!=null)
{document.write("<br />nextsibling: ");
document.write(x.nodeName);
document.write(" = ");
document.write(x.innerHTML);
get_nextSibling(x);}
else
{ document.write("到此为止");
}
}
function get_previousSibling(n){
var x=n.previousSibling;
if(x&&x.nodeType!=1){
x=x.previousSibling;
}
if(x!=null){
document.write(x.nodeName+x.nodeValue+x.nodeType+"<br />");
get_previousSibling(x);
}else
{document.write("没有更前面的节点了");
}
}
var my=document.getElementsByTagName("ul")[0].lastChild;
var x=document.getElementsByTagName("li")[0];
get_nextSibling(x);
document.write(my.nodeName);
get_previousSibling(my);
</script>
</body>
</html>