Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.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_Html_Twitter Bootstrap_Radio Button_Unchecked - Fatal编程技术网

在单击使用jquery时取消选中单选按钮

在单击使用jquery时取消选中单选按钮,jquery,html,twitter-bootstrap,radio-button,unchecked,Jquery,Html,Twitter Bootstrap,Radio Button,Unchecked,单选按钮仅在页面刷新时取消选中 <input type="radio" name="test"> 1<input type="radio" name="test">2 <input type="button" id="btn" /> $("#btn").click(function(){ $(':radio').each(function () { $(this).removeAttr('checked');

单选按钮仅在页面刷新时取消选中

<input type="radio" name="test">
    1<input type="radio" name="test">2
   <input type="button" id="btn" />

$("#btn").click(function(){

$(':radio').each(function () {
        $(this).removeAttr('checked');
        $('input[type="radio"]').attr('checked', false);
    })

}); 

12
$(“#btn”)。单击(函数(){
$(':radio')。每个(函数(){
$(this.removeAttr('checked');
$('input[type=“radio”]”)。attr('checked',false);
})
}); 
我制作了一把小提琴

但它不能与引导一起工作

使用而不是
。attr

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

使用以下方法:

 $(this).prop('checked', false);
 //$('input[type="radio"]').attr('checked', false);
您可以查看此以区分
.prop()
.attr()
.attr()
适用于访问HTML元素属性,如
(名称、id、类等)
.prop()
,用于大多数情况下返回布尔值的DOM元素属性

官方页面:

例如,应检索selectedIndex、tagName、nodeName、nodeType、ownerDocument、defaultChecked和defaultSelected,并使用.prop()方法进行设置。在jQuery1.6之前,可以使用.attr()方法检索这些属性,但这不在attr的范围内。这些属性没有相应的属性,只是属性


使用方便,以下内容将帮助您:

$("input:checked").removeAttr("checked");

检查更新的如果使用jQuery>1.5,则应使用
prop
而不是
attr

$('input[type="radio"]').prop('checked', false);
演示

有关详细信息,请参阅。

使用.prop()inbuild函数

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

.prop
只设置属性,不设置属性

或者您可以使用
is
来执行此操作

$("#btn").click(function(){
$("input[type='radio']").each(function() {
if($(this).is(':checked')){
  $(this).prop('checked',false);
   }
});
});

您可以为此创建一个JSFIDLE吗?