In Treeview, 1. When the parent node is selected, the child node is also selected. Otherwise ...... 2. Only one node can be selected and other items cannot be affected.

Source: Internet
Author: User
Tags tagname

// When the parent node is selected, the child node is selected at the same time ......
<Script language = "JavaScript" type = "text/JavaScript">
Function getcheck (){
VaR o = Window. event. srcelement;
If (O. tagname = "input" & O. type = "checkbox") // click the checkbox of Treeview to trigger
{
VaR d = O. ID; // obtain the ID of the current checkbox;

VaR E = D. Replace ("checkbox", "nodes"); // view the script information to obtain the ID of the DIV containing all child nodes.
VaR DIV = alert Doc ument. getelementbyid (E); // obtain the DIV object
If (Div! = NULL) // if it is not null, it indicates that a subnode exists.
{
VaR check = div. getelementsbytagname ("input"); // obtain all the tokens starting with input in the div.
For (I = 0; I <check. length; I ++ ){
If (check [I]. type = "checkbox") // if it is a checkbox
{
Check [I]. Checked = O. Checked; // The status of the byte point is the same as that of the parent node.
}

}

}
// Else // Changes the status of the parent node when the node is created, that is, not all nodes are selected.
//{
// Process the parent node
VaR divid = O. parentelement; // Div of the subnode

While (divid! = NULL ){

VaR id = divid. Id. Replace ("nodes", "checkbox"); // obtain the root node ID

VaR checkbox = divid. getelementsbytagname ("input"); // obtain the number of all subnodes
VaR S = 0;
For (I = 0; I <checkbox. length; I ++ ){
If (checkbox [I]. Checked) // determines how many subnodes are selected
{
S ++;
}
}

If (S = checkbox. Length) // if all the selected or selected child nodes of another root node,
{// The initial root node is still in the selected status.
Specified parameter Doc ument. getelementbyid (ID). Checked = true;
}
Else {// otherwise it is not selected
Specified parameter Doc ument. getelementbyid (ID). Checked = false;
}
Divid = invalid argument Doc ument. getelementbyid (ID). parentelement. parentelement;

}

}

}

// You can select only one node and cannot affect other items.
Function checkone ()
{
VaR o = event. srcelement;
If (O. tagname = "input" & O. type = "checkbox") // click the checkbox of Treeview to trigger
{
VaR divid = O. parentelement; // Div of the subnode

VaR checkbox = divid. getelementsbytagname ("input"); // obtain the number of all subnodes

For (VAR I = 0; I <checkbox. length; I ++)
{

If (checkbox [I]. type = "checkbox" & checkbox [I]! = O) // if it is checkbox
{

Checkbox [I]. Checked = false;

}

}

}
}

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.