日期:2014-05-16  浏览次数:20502 次

nextSibling的问题求助
a的父元素是li,li的nextSibling应该是下一个li,但alert出来为什么是#text呢?代码如下

<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html   xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<title> 无标题文档 </title>
<script   type= "text/javascript ">
<!--
function   test()
{
      var   ul1links   =   document.getElementById( "ul1 ").getElementsByTagName( "a ");
      for   (var   i   =   0   ;   i   <   ul1links.length   ;   i   ++   )
      {
            alert(ul1links[i].parentNode.nextSibling.nodeName);
      }
}

window.onload   =   function()
{
      test();
}
-->
</script>
</head>

<body>
<ul   id= "ul1 ">
<li> <a   href= "# "> li1 </a> </li>
<li> <a   href= "# "> li2 </a> </li>
<li> <a   href= "# "> li3 </a> </li>
</ul>
<ul   id= "ul2 ">
<li> <a   href= "# "> li4 </a> </li>
<li> <a   href= "# "> li5 </a> </li>
<li> <a   href= "# "> li6 </a> </li>
</ul>
</body>
</html>

------解决方案--------------------
ff把回行也看成是一个节点
把回行去掉就行了 类似这样:
<li> <a href= "# "> li1 </a> </li> <li> <a href= "# "> li2 </a> </li>