Jquery 单击其他复选框时如何从复选框中删除复选属性

Jquery 单击其他复选框时如何从复选框中删除复选属性,jquery,html,Jquery,Html,我有两个支票盒 <input type="checkbox" name="some" > <input type="checkbox" name="other" > 我想做的事情是,当我检查其中一个时,另一个应该自动取消检查。请记住,两个复选框的名称都更改为不同的名称。请帮帮我。先发制人 $('input[name="some"]').click(function(){ $('input[name="other"]').removeAttr('checked

我有两个支票盒

<input type="checkbox" name="some" >
<input type="checkbox" name="other" >

我想做的事情是,当我检查其中一个时,另一个应该自动取消检查。请记住,两个复选框的名称都更改为不同的名称。请帮帮我。先发制人

$('input[name="some"]').click(function(){
    $('input[name="other"]').removeAttr('checked');
});

$('input[name="other"]').click(function(){
    $('input[name="some"]').removeAttr('checked');
});
工作样本

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js"></script>
<input type="checkbox" name="some" >
<input type="checkbox" name="other" >

<script>
$('input[name="some"]').click(function(){
    $('input[name="other"]').removeAttr('checked');
});

$('input[name="other"]').click(function(){
    $('input[name="some"]').removeAttr('checked');
});

</script>

$('input[name=“some”]”)。单击(function(){
$('input[name=“other”]”)。删除属性('checked');
});
$('input[name=“other”]”)。单击(函数(){
$('input[name=“some”]”)。removeAttr('checked');
});
工作样本

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js"></script>
<input type="checkbox" name="some" >
<input type="checkbox" name="other" >

<script>
$('input[name="some"]').click(function(){
    $('input[name="other"]').removeAttr('checked');
});

$('input[name="other"]').click(function(){
    $('input[name="some"]').removeAttr('checked');
});

</script>

$('input[name=“some”]”)。单击(function(){
$('input[name=“other”]”)。删除属性('checked');
});
$('input[name=“other”]”)。单击(函数(){
$('input[name=“some”]”)。removeAttr('checked');
});

尝试使用单选按钮,因为这样您就不必添加任何javascript代码

单选按钮只允许一个选择。

尝试使用单选按钮,因为这样您就不必添加任何javascript代码

单选按钮只允许一个选择。

我认为在复选框上使用类,然后从那里调用函数是一个不错的选择。

我认为在复选框上使用类,然后从那里调用函数是一个不错的选择。

如果您使用的是jQuery v1.6或更高版本

$('input[name="some"]').click(function(){
    $('input[name="other"]').prop("checked", false);
});

单击“某些”复选框时,此代码取消选中“其他”复选框。

如果您使用的是jQuery v1.6或更高版本

$('input[name="some"]').click(function(){
    $('input[name="other"]').prop("checked", false);
});
$("input[type=checkbox]").click(function(){

  $('input[type=checkbox]').each(function () {
      $(this).prop("checked", false);
  }
   $(this).prop("checked", true);

});

单击“某些”复选框时,此代码将取消选中“其他”复选框。

为什么不使用单选按钮?(
)为什么不使用单选按钮?(
)我没听懂你的话。你想说什么?我没听懂。你想说什么?我能用这个$(“#some”)代替$('input[name=“some”]”)吗?阿赫桑·阿塔里:是的,如果你的ID值是一些,那么就可以了。不,我试过了,它仍然不起作用。attr(“checked”,false)。prop(“checked”,false)。removeAttr(“checked”)但它不起作用。我能用这个$(“#some”)代替$('input[name=“some”]))@阿桑·阿塔里:是的,如果你有一个ID值,那么它就可以了。不,它仍然不起作用,我试过了。attr(“checked”,false)。prop(“checked”,false)。removeAttr(“checked”),但它不起作用。很奇怪,它对我有效。用工作样本编辑答案。很奇怪,它对我有用。用工作样本编辑答案。
$("input[type=checkbox]").click(function(){

  $('input[type=checkbox]').each(function () {
      $(this).prop("checked", false);
  }
   $(this).prop("checked", true);

});