单选按钮“Checked = checked”当选项改变时不会改变 [英] Radio Button "Checked=checked" not changing when option changed

查看:1239
本文介绍了单选按钮“Checked = checked”当选项改变时不会改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个基本的2单选按钮形式,如下面的示例所示。

观察浏览器渲染,我们看到选择了项目1。我们检查项目1和2.



当我点击项目2时,我希望项目1的checked = checked被删除。我希望项目2获得检查=检查的属性。



这不是预期的行为吗?

 < div> 
< span>第1项< / span>
< input type =radioname =radio1id =radio1checked =checked/>
< / div>

< div>
< span>第2项< / span>
< input type =radioname =radio1class =checkboxid =radio2/>
< / div>

http://jsfiddle.net/chrimbus/ZTE7R/1/

解决方案

已检查 属性指定默认的选中的单选按钮,而不是当前选中的单选按钮。



请参阅此示例代码。点击第二个单选按钮,然后点击重置。然后再次点击第二个单选按钮,然后切换,然后重置。



选中的属性会给当前的 检查一个单选按钮的状态。




I've created a basic 2 radio button form as seen in my example below.

Observing the browser rendering, we see item 1 selected. We inspect item 1 and 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.

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>

http://jsfiddle.net/chrimbus/ZTE7R/1/

解决方案

The checked attribute specifies the default checked radio button, not the currently checked one.

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 property will give the current checked state of a radio button.

这篇关于单选按钮“Checked = checked”当选项改变时不会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆