如果使用jQuery选择了其他选项,则取消选中该复选框

如果使用jQuery选择了其他选项,则取消选中该复选框,jquery,Jquery,我有几个这样的复选框: <div class="col-sm-12"> <div class="col-sm-4"> <div class="checkbox checkbox-default"> <input type="checkbox" name="RAT_RoomList[]" value="10"> <label for="cus

我有几个这样的复选框:

<div class="col-sm-12">
        <div class="col-sm-4">
            <div class="checkbox checkbox-default">
                <input type="checkbox" name="RAT_RoomList[]" value="10">
                <label for="custome-checkbox1"># 11</label>
            </div>
        </div>
        <div class="col-sm-4">
            <div class="checkbox checkbox-default">
                <input type="checkbox" name="RAT_RoomList[]" value="11">
                <label for="custome-checkbox2"># 12</label>
            </div>
        </div>
        <div class="col-sm-4">
            <div class="checkbox checkbox-default">
                <input type="checkbox" name="RAT_RoomList[]" value="12">
                <label for="custome-checkbox3"># 13</label>
            </div>
        </div>
        <div class="col-sm-12">
            <div class="checkbox checkbox-default">
                <input type="checkbox" class="selectAll">
                <label for="custome-checkbox">Select all</label>
            </div>
        </div>
</div>

# 11
# 12
# 13
全选
如果选中了
Select all
,如何取消选中所有其他复选框;如果选中了其中一个复选框,如何取消选中
Select all


谢谢。

给你提琴


我想这就是你想要的。

在类中使用not选择器可以实现这一点

$('.selectAll')。单击(函数(){
if($(this).prop(“选中”,true)){
$(.col-sm-12”).find('input[type=checkbox')。not('.selectAll')。each(function(){
此项检查=错误;
});
}
});
$('input[type=checkbox]')。不是('.selectAll')。单击(函数(){
if($(this).prop(“选中”,true)){
$('.selectAll').prop(“选中”,false)
}
});

# 11
# 12
# 13
全选

选中“全选”时,为什么要取消选择所有其他选项?无论如何,您是否尝试将
单击
更改
处理程序添加到复选框中,并测试当前的
已选中
状态?如果它解决了您的问题,请告诉我。
$('.selectAll').change(function() {
    if ($(this).is(':checked')){
        $('input[name="RAT_RoomList[]"]').prop('checked', false);
    }
});

$('input[name="RAT_RoomList[]"]').change(function(){
    if ($(this).is(':checked')){
        $('.selectAll').prop('checked', false);
    }
});