this.parentElement.childNodes.length 这个不是得到<a>的子节点的数量么 怎么连自己也算进去? 而且算了两个?

解决方案 »

  1.   

    你把input后面的回车去掉,试一下就知道了
      

  2.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title></head><body>
    <a><input type="text" name="a"><input type="button" onClick="alert(this.parentElement.childNodes.length)" name="ok"></a>
    </body>
    </html>晕改成这样就成两个了  回车也算 ? 那这样准确率不是太低了么 还要注意把回车去掉