The effect of the method is: "When you change the selected state of a node, the selected state of its descendant node will also change with the current node's checked state." When the current node is selected, all its ancestor nodes are also checked, and when canceled, the selected state of its ancestors is determined based on whether the sibling node is selected. ”
Description: The tree is generated using the VS TreeView control.
As shown in figure:
The code is as follows:
Copy Code code as follows:
jquery (function () {
jquery (": CheckBox"). Click (function () {
var Objnode = this;
Var objnodeid=objnode.id;
var divobjid= objnodeid.substring (0,objnodeid.indexof ("checkbox")) </span>+ "Nodes";
JQuery (' # ' +divobjid+ ' input[type= ' checkbox '] '). each (function () {
this.checked=objnode.checked;
}
);
JQuery ("#" +objnodeid). Parents ("Div[id]"). each (function () {
var divid=this.id;
var cbid=divid.substring (0,divid.indexof ("Nodes")) + "checkbox";
var cbcount=jquery (' # ' +divid+ ' input:checked ');
If (objnode.checked| | cbcount.length==0)
{
var sid=document.getelementbyid (cbId);
if (sId)
{
sid.checked=objnode.checked;
}
}
}
);
});
});