<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <script type="text/javascript">
   function  window.onload(){
    var doc=document.getElementById("b1");
    alert(doc);             //[object HTMLIputElement]
    alert(doc.nextSibling); //[object Text]
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <input type="button" id="b1"  value="1"/>
    <input type="button" id="b2"  value="2"/>
    </div>
    </form>
</body>
</html>
//用nextSibling属性无法获得<input type="button" id="b2"  value="2"/>
属性,如果想用兄弟节点获得<input type="button" id="b2"  value="2"/>元素,该怎么做

解决方案 »

  1.   

    IE中空格换行也是节点doc.nextSibling,在ie中表示的是2个button中的换行
      

  2.   

    var doc=document.getElementById("b1");
    alert(doc);             //[object HTMLIputElement]
    alert(doc.nextSibling); //[object Text]
    var next = doc.nextSibling;
    if(next){
       while(next.nodeType == 3){//是文本节点
             next = doc.nextSibling;
       }
    }alert(next.id);
      

  3.   

    不好意思说反了,是在FF等非IE浏览器中,空格换行也是节点
    IE中会忽略掉这些的,doc.nextSibling代表的就是button2
      

  4.   

    var next=function(obj) {
     if(obj.nextElementSibling)
       return obj.nextElementSibling;
    return obj.nextSibling;
    }