这是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功能
最新推荐文章于 2021-04-01 22:24:03 发布