87,910
社区成员
发帖
与我相关
我的任务
分享
/* 改变"父级"checkbox为true */
top_group.each(function(){
console.log($(this).is(':checked'));
$(this).attr("checked",true);
console.log($(this).is(':checked'));
});
$(".son-group :checkbox").change(function(){
if($(this).is(':checked'))
{
var whether = true;
/* 查询点击checkbox的另外"同级的checkbox" */
var box_siblings = $(this).parents('.col-lg-6,.col-lg-offset-1').siblings().find(":checkbox");
/* 遍历另外"同级的checkbox",只要一个false,whether为false */
box_siblings.each(function(){
if(!$(this).is(':checked'))
{
whether = false;
}
});
/* 判定whether是否为true */
if(whether)
{
/* 查询点击checkbox的"父级"checkbox */
var top_group = $(this).parents('.son-group').prev().find(":checkbox");
/* 改变"父级"checkbox为true */
top_group.each(function(){
console.log($(this).is(':checked'));
$(this).attr("checked",true);
console.log($(this).is(':checked'));
});
}
}
else
{
/* 查询点击checkbox的"父级"checkbox */
var top_group = $(this).parents('.son-group').prev().find(":checkbox");
/* 改变"父级"checkbox为false */
top_group.each(function(){
$(this).attr("checked",false);
});
}
});