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;
}
}
}