Html 单选按钮“已检查=已检查”在选项更改时不会更改
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17836320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Radio Button "Checked=checked" not changing when option changed
提问by nthChild
I've created a basic 2 radio button form as seen in my example below.
我创建了一个基本的 2 个单选按钮表单,如下面的示例所示。
Observing the browser rendering, we see item 1 selected. We inspect item 1 and 2.
观察浏览器渲染,我们看到项目 1 被选中。我们检查项目 1 和 2。
When I click item 2, I expect item 1's checked=checked to be remove. I expect item 2 receive the attribute checked=checked.
当我单击第 2 项时,我希望删除第 1 项的 checked=checked。我希望项目 2 收到属性检查 = 检查。
Is this not the expected behavior?
这不是预期的行为吗?
<div>
<span>Item 1</span>
<input type="radio" name="radio1" id="radio1" checked="checked" />
</div>
<div>
<span>Item 2</span>
<input type="radio" name="radio1" class="checkbox" id="radio2" />
</div>
回答by Quentin
The checked
attributespecifies the defaultchecked radio button, not the currently checked one.
该checked
属性指定默认选中的单选按钮,而不是当前选中的单选按钮。
See this example code. Click the second radio button, then click Reset. Then click the second radio button again, then Switch, then Reset.
请参阅此示例代码。单击第二个单选按钮,然后单击重置。然后再次单击第二个单选按钮,然后切换,然后重置。
The checked propertywill give the currentchecked state of a radio button.
Checked属性将给出单选按钮的当前选中状态。