<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>是可以的啊!
<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>是可以的啊!
<img name="project"/>
<script>
alert(document.getElementsByName("project").length);
</script>
另,查了一下.name用于这些对象上的,应该会返回是正确的,除此之外的,可能不太"合法".
Anchor,Form,Input,Select,Textareat,Image,Window,Plugin
那应该有个函数叫getElementsById算了
<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();">
好像找到答案了
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一样的标签那?
这点有点奇怪哦.
以前有人说过Name和ID的区别,说ID是给DHTML用的,Name是给CGI/ASP/PHP/JSP用的.