Js implements the all-selected function for permission tree update.

Source: Internet
Author: User

Copy codeThe Code is as follows:
// JScript File
Function getParentByTagName (element, tagName)
{
Var parent = element. parentNode;
Var upperTagName = tagName. toUpperCase ();
While (parent & (parent. tagName. toUpperCase ()! = UpperTagName ))
{
Parent = parent. parentNode? Parent. parentNode: parent. parentElement;
}
Return parent;
}
Function setParentChecked (objNode)
{
Var objParentDiv = getParentByTagName (objNode, "div ");
If (objParentDiv = null | objParentDiv = "undefined ")
Return;
Var objID = objParentDiv. getAttribute ("ID ");
Var objParentCheckBox = document. getElementById (objID. replace ("Nodes", "CheckBox "));
If (objParentCheckBox = null | objParentCheckBox = "undefined ")
Return;
If (objParentCheckBox. tagName! = "INPUT" & objParentCheckBox. type = "checkbox ")
Return;
// Add
// If (objNode. checked = false) objPraentCheckBox. checked = false;
// ObjParentCheckBox. checked = true;
SetParentChecked (objParentCheckBox );
}
Function setParentUnChecked (objNode)
{
Var objParentDiv = getParentByTagName (objNode, "div ");
If (objParentDiv = null | objParentDiv = "undefined ")
Return;
Var objID = objParentDiv. getAttribute ("ID ");
Var objParentCheckBox = document. getElementById (objID. replace ("Nodes", "CheckBox "));
If (objParentCheckBox = null | objParentCheckBox = "undefined ")
Return;
If (objParentCheckBox. tagName! = "INPUT" & objParentCheckBox. type = "checkbox ")
Return;
// Add
// If (objNode. checked = false) objPraentCheckBox. checked = false;
ObjParentCheckBox. checked = false;
SetParentUnChecked (objParentCheckBox );
}
Function setChildCheckedState (div, state)
{
Var objchild = div. childNodes;
Var count = objchild. length;
For (var I = 0; I <objchild. length; I ++)
{
Var tempObj = objchild [I];
If (tempObj. tagName = "INPUT" & tempObj. type = "checkbox ")
{
TempObj. checked = state;
}
// Debugger;
SetChildCheckedState (tempObj, state );
}
}
Function TreeNodeChecked ()
{
Var objNode = window. event. srcElement;
If (objNode. tagName! = "INPUT" | objNode. type! = "Checkbox ")
Return;
// Debugger;
If (objNode. checked = true)
{
SetParentChecked (objNode );
}
Else
{
SetParentUnChecked (objNode );
}
Var objID = objNode. getAttribute ("ID ");
Var objParentDiv = document. getElementById (objID. replace ("CheckBox", "Nodes "));
If (objParentDiv = null | typeof (objParentDiv) = "undefined ")
Return;
SetChildCheckedState (objParentDiv, objNode. checked );
}
Function SetTreeNodeChecked (objNode1)
{
Var objNode = objNode1;
Var objID = objNode. getAttribute ("ID ");
Var objParentDiv = document. getElementById (objID. replace ("CheckBox", "Nodes "));
If (objParentDiv = null | typeof (objParentDiv) = "undefined ")
Return;
SetChildCheckedState (objParentDiv, objNode. checked );
}
Function GetYHQS (id)
{
PageMethods. CallYHQX (id, callsuccessed );
}
Function callsuccessed (result)
{
/// Cycle page
// Debugger;
For (I = 0; I <document. form1.length; I ++)
{
Var objNode = document. form1.elements [I];
If (objNode. tagName = "INPUT" & objNode. type = "checkbox ")
{
ObjNode. checked = false;
}
}
For (I = 0; I <document. form1.length; I ++)
{
Var objNode = document. form1.elements [I];
If (objNode. tagName = "INPUT" & objNode. type = "checkbox ")
{
// Find
// Compare
If (result. indexOf (objNode. title )! =-1)
{
ObjNode. checked = true;
SetTreeNodeChecked (objNode );
}
}
}
}
Function test ()
{
Debugger;
// Loop page
For (I = 0; I <document. form1.length; I ++)
{
Var objNode = document. form1.elements [I];
If (objNode. tagName = "INPUT" & objNode. type = "checkbox ")
{
// Find
// Compare
ObjNode. checked = true;
}
}
}

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.