getElementsByName无法获得Div

<input name="test" type="radio" id="r1">
<input name="test" type="radio" id="r2">
<input name="test" type="radio" id="r3">

<div name="myName" id="Div1"></div>
<div name="myName" id="Div2"></div>

[color=red]document.getElementsByName("test").length returns 4
document.getElementsByName("myName").length returns 0[/color]

why?答案是:div标签根本就没有name属性;所以通过getElementsByName()是得不到div的!


look the DOM documentation:
[quote]
When you use the getElementsByName method, all elements in the document that have the specified NAME or ID attribute value are returned.

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?A HREF="../properties/expando.html">expando.

[/quote]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值