Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.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 匹配元素的Jquery检查列表_Javascript_Jquery - Fatal编程技术网

Javascript 匹配元素的Jquery检查列表

Javascript 匹配元素的Jquery检查列表,javascript,jquery,Javascript,Jquery,我使用属性rel将一些复选框分组。当任何人都未检查时,我想检查是否所有人都未检查,然后做一些事情 场景:我有一个父复选框,表示所有子项都未选中,父项应该被选中。如果选中一个或多个,则需要检查父项 所有子复选框都有类名child $('.child').change(function () { var groupdId = $(this).attr('rel'); if($('.child').where('rel', groupId).any('checked', true)) &l

我使用属性
rel
将一些复选框分组。当任何人都未检查时,我想检查是否所有人都未检查,然后做一些事情

场景:我有一个父复选框,表示所有子项都未选中,父项应该被选中。如果选中一个或多个,则需要检查父项

所有子复选框都有类名
child

$('.child').change(function () {
   var groupdId = $(this).attr('rel');
   if($('.child').where('rel', groupId).any('checked', true)) <-- how do I do this?
   {
       //Uncheck the parent
   }
   else {
       //Check the parent.
   }
});
$('.child').change(函数(){
var groupdId=$(this.attr('rel');
if($('.child').where('rel',groupId.).any('checked',true))
$('.child[rel=“'+groupId+'”):checked')。长度>0

[rel=…]
是一种针对属性进行选择的方法

:选中的
是一个jQuery psuedo选择器


未经测试,但我认为这会起作用

var $boxes = $('input.child');

$boxes.click(function() {
    var $box = $(this),
        grp = $box.attr('rel'),
        $boxes_in_group = $boxes.filter("[rel='"+ grp +"']");

    if ( $box[0].checked )
        // Check the parent.
    else if ( $boxes_in_group.filter(":checked").length == 0 )
        // Uncheck the parent.
});
var $boxes = $('input.child');

$boxes.click(function() {
    var $box = $(this),
        grp = $box.attr('rel'),
        $boxes_in_group = $boxes.filter("[rel='"+ grp +"']");

    if ( $box[0].checked )
        // Check the parent.
    else if ( $boxes_in_group.filter(":checked").length == 0 )
        // Uncheck the parent.
});