如果没有选中复选框,我该如何.slideUp那个父div?
if ($("input:checkbox:not(:checked)")) {
$("#parentOfParentDiv").slideUp();
// this should slide up the entire parent div IF NONE is selected, doesnt work
} else {
$("input:checkbox:not(:checked)").closest('div').slideUp();
//this should slideUp all the divs that are NOT checked, this works
}
答案 0 :(得分:0)
检查已选中复选框的长度
if ($("input:checkbox:checked").length >0) {
$("input:checkbox:not(:checked)").closest('div').slideUp();
} else {
$("#parentOfParentDiv").slideUp();
}
答案 1 :(得分:0)
如果我理解正确,您应该检查已选中复选框的长度:
if (!$("input:checkbox:checked").length) { // nothing is checked
$("#parentOfParentDiv").slideUp();
} else {
$("input:checkbox:not(:checked)").closest('div').slideUp();
}
答案 2 :(得分:0)
你需要这个:
if (!$(":checkbox").is(":checked")) {
$("#parentOfParentDiv").slideUp();
} else { $("input:checkbox:not(:checked)").closest('div').slideUp(); }