How can I use scripts to implement the parent-child node linkage function of TreeView? Due to Firefox's own characteristics, do not use scripts in IE for implementation, and use. cs code for implementation in Firefox. Because these two browsers have poor compatibility, Ai!
Okay, let's talk nonsense. Now, we will first provide the script method for implementing the association of the TreeView parent and child nodes:
Function ChcekFuncNodes (e)
{
Var I = e. clickedNodeIndex;
Var node = e. getTreeNode (I );
Var NodeArray = node. getChildren ();
If (NodeArray. length> 0)
{
If (node. getAttribute ("Checked") = true)
{
For (var I = 0; I <NodeArray. length; I ++)
{
CheckTreeNode (NodeArray [I], true, false );
GetSelectedFunctionPointID (NodeArray [I]);
}
GetSelectedFunctionID (node );
}
Else
{
For (var I = 0; I <NodeArray. length; I ++)
{
CheckTreeNode (NodeArray [I], false, false );
}
}
}
Else
{
Var ParentNode = node. getParent ();
If (ParentNode! = Null)
{
If (node. getAttribute ("Checked") = true)
{
GetSelectedFunctionPointID (node );
CheckTreeNode (ParentNode, true, false );
GetSelectedFunctionID (ParentNode );
}
Else
{
If (AllChildTreeNodeSameCheck (ParentNode, false ))
{
CheckTreeNode (ParentNode, false, false );
}
}
}
Else
{
CheckTreeNode (node, true, false );
GetSelectedFunctionID (node );
}
}
} Function CheckTreeNode (chilNode, isCheck, atuoSetChilTreeNode)
{
If (chilNode! = Null)
{
// Alert (chilNode );
ChilNode. setAttribute ('checked', isCheck );
If (atuoSetChilTreeNode)
{
CheckChildTreeNode (chilNode, isCheck)
}
}
} Function CheckChildTreeNode (Pnode, isCheck)
{
If (Pnode! = Null)
{
Var arr = Pnode. getChildren ();
For (var I = 0; I <arr. length; I ++)
{
Arr [I]. setAttribute ('checked', isCheck );
}
}
} Function AllChildTreeNodeSameCheck (PareNode, value)
{
If (PareNode! = Null)
{
Var chids = PareNode. getChildren ();
For (var I = 0; I <chids. length; I ++)
{
If (chids [I]. getAttribute ("Checked ")! = Value)
{
Return false;
}
}
}
Return true;
}
As we all know, there is no need to talk about it. The following two methods are used to record the FunctionID and FunctionPointID selected by the user and pass it. the cs file is used to add why I use document. getElementById ('<% = hidenFunID. clientID %> ') instead of document. getElementById ('hienfunid ')? The reason is that my script is placed in the ascx file (that is, in UserControl), so you can only find the control in this way, otherwise you will not be able to find it! A little trick.
Function GetSelectedFunctionID (nodes)
{
Var hideFun = document. getElementById ('<% = hidenFunID. ClientID %> ');
Var checkFun = hideFun. value;
CheckFun + = nodes. getAttribute ("ID") + ";";
HideFun. value = checkFun;
// Alert (hideFun. value );
} Function GetSelectedFunctionPointID (nodes)
{
Var hideFunPoint = document. getElementById ('<% = txtPointId. ClientID %> ');
Var checkFun = hideFunPoint. value;
CheckFun + = nodes. getAttribute ("ID") + ";";
HideFunPoint. value = checkFun;
// Alert (hideFunPoint. value );
}
In the last step, let the Parent and Child Nodes of the TreeView interact to produce real results ................. private void Page_Load (object sender, System. eventArgs e)
{
If (! Page. IsPostBack)
{
TvRoleFunctions. Attributes. Add ("oncheck", "ChcekFuncNodes (this )");
}
}
Next writing notice:
How to Implement the Select All TreeView function for All nodes? How can we expand and collapse freely?