这是MSDN的解释: Elements that support both the NAME and the ID attribute are included in the collection returned by the getElementsByName method, but not elements with a NAME expando. 就是说,对于IE来说,id和name是通用的,这样就可以通过设置多个div的id相同,通过getElementsByName方法获取一组div对象(我只测试了IE6). 对于firefox和chrome(同safari)来说是有name属性的,即通过设置name即可实现(测试了chrome3.0.195.25,firefox3.0.11). 例子
div不管有没有name属性,只要设置id和name为同一个值即可实现getElementsByName功能
最新推荐文章于 2018-08-21 16:31:54 发布
本文探讨了在不同浏览器中使用ID和NAME属性的方法。对于IE浏览器,ID和NAME属性可以互换使用;而对于Firefox和Chrome等浏览器,则需正确设置NAME属性。文章通过实例展示了如何在各种浏览器中实现一致的行为。
2万+

被折叠的 条评论
为什么被折叠?



