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.
});