document.getElementById('1').getElementsByName("sss").length
用这个不行诶...

解决方案 »

  1.   

    运行一下这个你就知道为什么不行了
    document.getElementById("1")得到的对象没有getElementsByName个方法
    <!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=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript">
    function ready()
    {
    ShowObjProperty(document.getElementById("1")) 
    ShowObjProperty(document) 
    }function ShowObjProperty(Obj) 

    var PropertyList=''; 
    var PropertyCount=0; 
    for(i in Obj){ 
    if(Obj.i !=null) 
    PropertyList=PropertyList+i+'属性:'+Obj.i+'\r\n'; 
    else 
    PropertyList=PropertyList+i+'方法\r\n'; 
    PropertyList += '<br />';


    document.write(PropertyList ); 
    } </script>
    </head>
    <body onload="ready()">
    <div id="1">
    <input name="sss" type="text" />
    <input name="sss" type="text" />
    <input name="sss" type="text" />
    <input name="sss" type="text" />
    </div>
    <input name="sss" type="text" />
    </body>
    </html>
      

  2.   

    貌似只能有document才有getElementsByName方法。
    要实现JQuery的这个选择器,可以这样:取id为1的元素下的子元素和文档中name为sss的元素这两个列表的交集。
    老麻烦的感觉哦。
      

  3.   

    我估计jquery都是用正则去匹配的
      

  4.   

    网上看了下,他的选择器确实是用正则实现的http://wenku.baidu.com/view/421c86c489eb172ded63b73f.html呵呵