<table id="project">
 <tr><td>sssss</td></tr>
</table>
 <table id="project">
 <tr><td>sssss</td></tr>
</table> 
<table id="project">
 <tr><td>sssss</td></tr>
</table>
<script>
alert(document.getElementsByName("project").length);
document.getElementsByName("project")[0].height = 200;
</script>是可以的啊!

解决方案 »

  1.   

    我的意思是不用ID,用NAME为什么不行
      

  2.   

    个人以为是因为name用在Table上不太"规范"你看看这<img name="project"/>
    <img name="project"/>
    <script>
    alert(document.getElementsByName("project").length);
    </script>
    另,查了一下.name用于这些对象上的,应该会返回是正确的,除此之外的,可能不太"合法".
    Anchor,Form,Input,Select,Textareat,Image,Window,Plugin
      

  3.   

    那也就是说只能用ID了?
    那应该有个函数叫getElementsById算了
      

  4.   

    很奇怪.
    <table name="project">
     <tr><td>sssss</td></tr>
    </table>
     <table name="project">
     <tr><td>sssss</td></tr>
    </table> 
    <table name="project">
     <tr><td>sssss</td></tr>
    </table>
    <input type=radio name="radio2" disabled>222
    <input type=radio name="radio2" disabled>222
    <br>
    <script>
    function showInfo()
    {
    alert(document.getElementsByName("project").length);
    alert(document.getElementsByName("project").item.length);
    alert(document.getElementsByTagName("Table").length)
    window.confirm(document.getElementsByName("radio2").length);
    }
    </script>
    <input type=button onclick="showInfo();">
      

  5.   

    翻了下手册,
    好像找到答案了
    When you use the getElementsByName method, all elements in the document that have the specified NAME attribute value are returned.Elements that support the NAME attribute are included in the collection returned by the getElementsByName method, but not elements with a NAME expando.好像只有支持name属性的元素才能被正确返回.
    又看了一下支持name的标签:
    A, APPLET, BUTTON, FORM, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=hidden, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, LINK, MAP, OBJECT, PARAM, RT, RUBY, SELECT, TEXTAREA 
    不过用getElementsByName怎么会返回ID一样的标签那?
    这点有点奇怪哦.
      

  6.   


    以前有人说过Name和ID的区别,说ID是给DHTML用的,Name是给CGI/ASP/PHP/JSP用的.
      

  7.   

    手边没有手册,这个item是个什么东东哦?alert(document.getElementsByName().item.length)楼主说的“不过在操作集合中的对象的时候就会出现问题”是指什么问题?