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

Source: Internet
Author: User
A few days ago, in order to improve the tree-based permission selection function, jquery was used to write a method based on the tree structure. 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:

The Code is as follows:


JQuery (function (){
JQuery (": checkbox"). click (function (){
Var objNode = this;
Var objNodeId = objNode. id;
Var pObjId = objNodeId. substring (0, objNodeId. indexOf ("CheckBox") </span> + "Nodes ";
JQuery ('#' + pObjId + 'input [type = "checkbox"] '). each (function (){
This. checked = objNode. checked;
}
);
JQuery ("#" + objNodeId). parents ("p [id]"). each (function (){
Var pId = this. id;
Var cbId = pId. substring (0, pId. indexOf ("Nodes") + "CheckBox ";
Var cbCount = jQuery ('#' + pId + '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.