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

Source: Internet
Author: User

The result of this method is: "When a node is selected, the selected status of its child nodes also changes with the selected status of the current node. When the current node is selected, all its ancestor nodes should also be selected. If the node is canceled, the selected state of its ancestor node should be determined based on whether the same level node is selected ."
Note: The tree is generated using the TreeView control of.


The Code is as follows:
Copy codeThe Code is 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;
}
}
}
);
});
});

Related Article

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.