Jquery,如何取消选择单选组中的所有单选按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12054825/
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
Jquery, How to unselect all radio button in radio group
提问by Alexis C.
Anyone know how to unselect all radio buttons in a radio group ?
任何人都知道如何取消选择单选组中的所有单选按钮?
HTML:
HTML:
<div id="emptimfields">
<label id="lbl_emptim">How regulary do you employ people to help cultivate your land? </label><br/><br/>
<fieldset data-role="controlgroup" data-type="vertical" id="emptim">
<input name="emptim" id="radio1" value="fromtimetotime" type="radio" openmrs-valuecoded="" />
<label for="radio1"> From time to time </label>
<input name="emptim" id="radio2" value="allthetime" type="radio" openmrs-valuecoded="" />
<label for="radio2">All the time</label>
<input name="emptim" id="radio3" value="dontknow" type="radio" openmrs-valuecoded="" />
<label for="radio3"> Don't know </label>
</fieldset>
</div>
JQuery side:
JQuery 端:
$('input:radio[name=emptim]:checked').prop('checked', false); // doesn't work
I'm certainly missing something basic, but I can't figure out what is the problem.
我当然缺少一些基本的东西,但我无法弄清楚是什么问题。
First, I check Yes and then check a value of the second radio group :
首先,我检查 Yes 然后检查第二个无线电组的值:
Then, I check No to hide the second radio group:
然后,我选中 No 以隐藏第二个无线电组:
Then, If I click on next, I get the value of what I've checked (but I checked no previously, so here I don't want an alert, I want the radioButton "From time to time" to be unchecked) :
然后,如果我点击下一步,我会得到我检查过的值(但我之前没有检查过,所以在这里我不想要警报,我希望不选中单选按钮“不时”):
Finally, if I come back, nothing happend :
最后,如果我回来,什么也没有发生:
回答by Roel
You can give them a classname and try:
你可以给他们一个类名并尝试:
$('.classname').prop('checked', false);
When you use an older version of jQuery than 1.6 it has to be:
当您使用比 1.6 旧版本的 jQuery 时,它必须是:
$('<selector>').attr('checked', false);
EDIT :
编辑 :
Call the method .checkboxradio("refresh");
has also worked for me.
调用该方法.checkboxradio("refresh");
也对我有用。
回答by user1841830
$('input:radio[name=indicatorType]').each(function () { $(this).prop('checked', false); });
Alternative solution for making 'unchecked' whole radio buttons of a radio group('indicatorType' for above code sample).
用于制作单选组的“未选中”整个单选按钮的替代解决方案(上述代码示例中的“indicatorType”)。
回答by Phill Healey
This should do it. Notice the refresh option at the end to force the controlgroup to be updated.
这应该这样做。请注意末尾的刷新选项以强制更新控制组。
An additional benefit of this method is that it targets a specific radio group by name, rather than all radio controls on a page.
这种方法的另一个好处是它按名称针对特定的无线电组,而不是页面上的所有无线电控件。
$('input:radio[name=emptim]:checked').prop('checked', false).checkboxradio("refresh");
回答by Jaggana
The prop doesnt works for me, bu this works perfectly :
该道具对我不起作用,但这非常有效:
('input:radio[name="RadioName"]').each(function () { $(this).attr('checked', false); });