因为他把后边的空白换行也算上了 你这个样试试
<div id="aDiv"> 
    <input type="text" ...><input type="button" ...></div> 

解决方案 »

  1.   

    我晕.. 怎么发不去就带空白呢
    <div id="aDiv"><input type="text" ...><input type="button" ...></div>
      

  2.   

    有空格也会当作一个子节点<div id="aDiv"><input  type="text"/><input type="text" /></div> 
      

  3.   

    的确是2个子元素,
    但还有2个子节点,都是文本节点<div id="aDiv"> 
        <input type="text"> 
        <input type="button"> 
    </div><script>
    var obj=document.getElementById("aDiv");
    var childNodes = obj.childNodes;
    for (var i = 0; i < childNodes.length; i++) {
    document.write(childNodes[i].nodeType + " ");
    if (childNodes[i].nodeType == 3) {
    document.write("[" + childNodes[i].nodeValue + "] ");
    }
    document.write("<br>");
    }
    </script>以上代码运行后,会输出

    3 [ ] 

    3 [ ] 其中1代表元素节点
    3代表文本节点,其实就是回车换行加空白符
      

  4.   

    L@_@K
    <!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>
      <title> new document </title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
     </head> <body>
    <div id="aDiv"> 
    <input type="text" value="123" /> 
    <input type="button" value="btn" /> 
    </div>
    <script type="text/javascript">
    <!--
    function getElementNodes(oParent)
    {
    var elementNodes = new Array();
    for (var i=0; i<oParent.childNodes.length; i++)
    {
    if (oParent.childNodes[i].nodeType == 1)
    {
    elementNodes.push(oParent.childNodes[i]);
    }
    }
    return elementNodes;
    }
    var obj = document.getElementById("aDiv"); 
    alert(getElementNodes(obj).length);
    //-->
    </script>
     </body>
    </html>