开发者

Does setting the checked attribute on a radio button change the checked attributed on other buttons with the same name?

开发者 https://www.devze.com 2023-03-04 02:51 出处:网络
If I have a group of radion buttons, with one being set as checked by default: <input type=\"radio\" id=\"id1\" name=\"grp\" value=\"val1\" checked=\"checked\">

If I have a group of radion buttons, with one being set as checked by default:

<input type="radio" id="id1" name="grp" value="val1" checked="checked">
<input type="radio" id="id2" name="grp" value="val2"&开发者_开发技巧gt;
<input type="radio" id="id3" name="grp" value="val3">

If I now get the element with ID "id2" and do

var el = ...;
el.checked = true;

will the checked property for the other elements automatically be set to false?

Bonus points for a link to official documentation describing the behavior.


Does setting the checked attribute on a radio button change the checked attributed on other buttons with the same name?

Yes, it does. I'm surprised to find that this behavior isn't clearly documented in the DOM2 HTML specification. It is, though, documented in the HTML5 specification and the HTML 4.01 specification.

Gratuitous live example

0

精彩评论

暂无评论...
验证码 换一张
取 消