Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jQuery取消选择单选按钮组_Jquery_Radio Button - Fatal编程技术网

使用jQuery取消选择单选按钮组

使用jQuery取消选择单选按钮组,jquery,radio-button,Jquery,Radio Button,我正在使用jQuery,我有一组单选按钮,它们都具有相同的名称,但值属性不同 例如: <input type = "radio" name = "thename" value="1"></input> <input type = "radio" name = "thename" value="2"></input> <input type = "radio" name = "thename" value="3"></input&g

我正在使用jQuery,我有一组单选按钮,它们都具有相同的名称,但值属性不同

例如:

<input type = "radio" name = "thename" value="1"></input>
<input type = "radio" name = "thename" value="2"></input>
<input type = "radio" name = "thename" value="3"></input>


我想让他们都不被选中。我的页面的当前状态已单击其中一个。如何执行此操作?

请尝试以下代码:

$(input[name=thename]).removeAttr('checked');
$(input[name=thename]).removeAttr('checked');
尝试使用以下命令:
$('input[type=“radio”]”)。prop('checked',false)

使用jQuery的方法可以更改元素的属性(选中、选中等)。

从jQuery 1.6开始,
$(“radio”).prop(“选中”,false)
是建议的方法

$("input:radio[name='thename']").each(function(i) {
       this.checked = false;
});

不知道为什么jquery道具不起作用,这确实起作用了…

由@matzahboy发布的答案非常有效

尝试了其他方法,但这一种效果最好:


这允许您双击收音机以重置它们。

要取消选择名为“名称组”的组的所有收音机,请尝试以下操作:

$("input[type=radio][name=namegroup]").prop("checked", false);

这是一个简单而通用的答案(我相信):
$(“输入[name=name\u您的无线组]”).prop(“选中”,false)

对于这个具体问题,我将使用:

$(“input[name=thename]”)prop(“checked”,false)

希望这对我有用

它对我有用

$('input[name="radioName"]').attr('checked', false);

这很简单,适合我

试试这个:

$('input:radio[name="gender"]').attr('checked',false);
$('input[name="gender"]').prop('checked', false);
试试这个:

$('input:radio[name="gender"]').attr('checked',false);
$('input[name="gender"]').prop('checked', false);

对不起,这对我不起作用。我试过了。另外,如果页面上有其他无线电元素,而我不想将该行为应用于它们,该怎么办?只要尝试更改选择器即可。类似于
$(“input[name='thename'])”
当我在右括号后面添加了一个单独的引号--$('input[type=“radio”]').prop('checked',false)时,对这一点进行了很好的讨论@JimEvans谢谢你。我不知道为什么直到现在我才看到。我已经编辑了答案以获得结束引用。不起作用,但两者都起作用:$(“输入:radio[name='thename']”)。removeAttr('checked')$(“[name='thename']”).removeAttr('checked');周围的记号是可选的。