[英]How to avoid unchecking parent node when child node is unchecked
I have a java script where all child nodes are checked when parent node is checked but my problem is when I'm unchecking child node, parent node is also unchecked.I dont want my parent node to uncheck when child node is unchecked. 我有一个Java脚本,其中在检查父节点时检查所有子节点,但是我的问题是在取消选中子节点时也未选中父节点。我不希望我的父节点在未选中子节点时取消选中。 My script is
我的剧本是
<script type="text/javascript">
$(function chkitemscript() {
$("[id*=TreeView1] input[type=checkbox]").bind("click", function () {
var table = $(this).closest("table");
if (table.next().length > 0 && table.next()[0].tagName == "DIV") {
//Is Parent CheckBox
var childDiv = table.next();
var isChecked = $(this).is(":checked");
$("input[type=checkbox]", childDiv).each(function () {
if (isChecked) {
$(this).attr("checked", "checked");
} else {
$(this).removeAttr("checked");
}
});
} else {
//Is Child CheckBox
var parentDIV = $(this).closest("DIV");
if ($("input[type=checkbox]", parentDIV).length == $("input[type=checkbox]:checked", parentDIV).length) {
$("input[type=checkbox]", parentDIV.prev()).attr("checked", "checked");
} else {
$("input[type=checkbox]", parentDIV.prev()).removeAttr("checked");
}
}
});
})
</script>
else {
//Is Child CheckBox
var parentDIV = $(this).closest("DIV");
if ($("input[type=checkbox]", parentDIV).length == $("input[type=checkbox]:checked", parentDIV).length) {
$("input[type=checkbox]", parentDIV.prev()).attr("checked", "checked");
} else {
$("input[type=checkbox]", parentDIV.prev()).removeAttr("checked");
}
}
Please remove the above else part this may work 请删除上面的其他部分,这可能会起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.