Jquery,如何取消选择单选组中的所有单选按钮

标签 jquery html jquery-mobile jquery-selectors

有人知道如何取消选择单选组中的所有单选按钮吗?

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 端:

$('input:radio[name=emptim]:checked').prop('checked', false); // doesn't work 

我当然遗漏了一些基本的东西,但我不知道是什么问题。

首先,我检查是,然后检查第二个 radio 组的值:

enter image description here

然后,我选中否以隐藏第二个单选组:

enter image description here

然后,如果我点击下一步,我会得到我检查过的值(但我之前没有检查过,所以在这里我不想要一个警报,我希望单选按钮“不时”是未选中):

enter image description here

最后,如果我回来,什么也没有发生:

enter image description here

最佳答案

你可以给他们一个类名并尝试:

$('.classname').prop('checked', false);

当你使用比 1.6 更旧的 jQuery 版本时,它必须是:

 $('<selector>').attr('checked', false);

编辑:

调用方法 .checkboxradio("refresh"); 也对我有用。

关于Jquery,如何取消选择单选组中的所有单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12054825/

相关文章:

javascript - 如何从输入中获取值并添加到href jquery

jquery镜头变焦完美定位

html - 自定义元素的名称中是否需要破折号?

c# - 如何将波浪号的相对路径呈现为 ../../jquery/javascript 中的相对路径?

html - 如何在 jquery mobile 中为单个 select.option 元素指定字体系列?

javascript - 使用 jQuery 更改对象宽度和窗口大小

javascript - 从字符串中删除软连字符

javascript - 如何在 React JS 中为文本设置颜色

css - JQuery 移动版 : Replace thumbnail with data element

javascript - 如何消除页面切换之间的闪烁? (JQuery 移动)