Select the JS method (jquery) for the tree data node of the TreeView control _jquery

Source: Internet
Author: User
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;
}
}
}
);
});
});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.