Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.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/2/jquery/75.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
Javascript 如何取消选中';选择全部';复选框如果任何子复选框未选中_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何取消选中';选择全部';复选框如果任何子复选框未选中

Javascript 如何取消选中';选择全部';复选框如果任何子复选框未选中,javascript,jquery,html,Javascript,Jquery,Html,我已经提供了一个代码,单击选择所有复选框,选择child 复选框被选中/取消选中。现在如果我取消选中任何子复选框, 应取消选中“全选”复选框。我该怎么办 $(文档).ready(函数(){ $(“#全选”)。单击(函数(事件){ var$that=$(this); $(':复选框')。每个(函数(){ this.checked=$that.is(':checked'); }); }); }); 用户名 用户Id 任命 电话号码 地址 曼迪普库姆哈尔酒店 employee@123 安全负责人

我已经提供了一个代码,单击
选择所有
复选框,选择child
复选框被选中/取消选中。现在如果我取消选中任何子复选框,
应取消选中“全选”复选框。我该怎么办

$(文档).ready(函数(){
$(“#全选”)。单击(函数(事件){
var$that=$(this);
$(':复选框')。每个(函数(){
this.checked=$that.is(':checked');
});
});
});

用户名
用户Id
任命
电话号码
地址
曼迪普库姆哈尔酒店
employee@123
安全负责人
123456789
孟买库尔勒东部尼赫鲁纳加尔Neelkanth CHS 18/522-400024
曼迪普库姆哈尔酒店
employee@123
安全负责人
123456789
awtry lbduyvetyd jhvdytf ihuusb
曼迪普库姆哈尔酒店
employee@123
安全负责人
123456789
awtry lbduyvetyd jhvdytf ihuusb

若要取消选中,请在用户取消选中任何复选框时选择全部,请在下面的代码中尝试

$('.checkbox').click(function(){
   if($(this).prop("checked") == false){
   $('#select-all').prop('checked', false);
   }
}

您可以为“子类”复选框指定类,并为“已选中”复选框指定条件

$('checkall')。在('change',function()上{
$('.test:checkbox').prop('checked',$(this).is(“:checked”);
});
$('.test')。在('change',function()上{
如果(!$(this).is(':checked')){
$('.test').prop('checked',false);
$('checkall').prop('checked',false);
}
如果($('.test:checked')。长度===1){
$('.test').prop('checked',false);
$('checkall').prop('checked',false);
}
});

全部检查
1.
2.
3.

4
在“更改孩子”复选框中执行操作

$('.checkbox').change(function(){
   if($(this).prop("checked") == false){
   $('#select-all').prop('checked', false);
   }
}

我建议如下,它允许
#select all
元素选中所有“child”复选框,并允许这些子复选框选中或取消选中
#select all

// caching the <table> element:
var tableElement = $('table');

// binding the anonymous function of the on() method to the
// 'change' event that takes place on <input> elements of
// type=checkbox:
tableElement.on('change', 'input[type=checkbox]', function(event) {

  // caching the changed element:
  var changed = event.target,

  // caching:
    checkboxes = tableElement

    // <input> elements within the <table>
    // of type=checkbox:
    .find('input[type=checkbox]')

    // which do not match the '#select-all'
    // selector:
    .not('#select-all');

  // if the changed element has the id of 'select-all':
  if (changed.id === 'select-all') {

    // we update the 'checked' property of the cached
    // check-box inputs to reflect the checked state
    // of the '#select-all' element:
    checkboxes.prop('checked', changed.checked);
  } else {

    // here we check that the number of checked checkboxes
    // is equal to the number of check-boxes (effectively
    // finding out whether all, or not-all, check-boxes are
    // checked:
    var allChecked = checkboxes.length === checkboxes.filter(':checked').length

    // here we update the 'checked' property of the
    // '#select-all' check-box to true (if the
    // number of checked check-boxes is equal to the
    // number of check-boxes) or false (if the number
    // of checked check-boxes is not equal to the
    // number of check-boxes):
    $('#select-all').prop(
      'checked', allChecked
    );

  }
});

用户名
用户Id
任命
电话号码
地址
曼迪普库姆哈尔酒店
employee@123
安全负责人
123456789
孟买库尔勒东部尼赫鲁纳加尔Neelkanth CHS 18/522-400024
曼迪普库姆哈尔酒店
employee@123
安全负责人
123456789
awtry lbduyvetyd jhvdytf ihuusb
曼迪普库姆哈尔酒店
employee@123
安全负责人
123456789
awtry lbduyvetyd jhvdytf ihuusb

也添加您的
html
。检查