複製程式碼 程式碼如下: ><BR><BR><script language="java">><P><script language="java">> * <BR>函數名稱:CheckNode(currentNode)、ParentNode(currentNode)、ChildNode(currentNode) <BR> 函數功能:實現帶有checkbox的treeview中 <P>1.選取父結點其子結點也全部選取 <BR>2、取消全部子結點的選擇後,父結點的選擇也隨之取消 <P>使用方法:<BR>1、在<head>中間加入CheckNode(currentNode)、ParentNode(currentNode)、ChildNode(currentNode) <br> <br>2、在*.aspx.cs的Page_load()事件中加入yourTreeView.Attribute.Add("OnCheck","CheckNode(yourTreeView.getTreeNode(yourTreeView.clickedNodeIndex))") <BR> > <BR> //遞歸遍歷所有子節點 <BR> function CheckNode(currentNode) <BR> { <BR> child <BR> var isChecked; <BR> childNode=currentNode.getChildren(); <BR> if(currentNode.getAttribute('checked')) <BR> { <BR> { <BR> isChecked=false; <BR> } <BR> //父節點處理 <BR> if(currentNode.getParent()!=null) ('Checked')) <BR> { <BR> ParentNode(currentNode); <BR> } <BR> 🎜> } <BR> } <BR> else <BR> { <BR> //什麼都不做 <BR> } <🠟> <BR> for(var i=0;i<childNode.length;i ) <BR> { <BR> childNode.setAttribute("Checked",isChecked); <> > { <BR> CheckNode(childNode); <BR> } <BR> } <BR> } <🟠 currentNode) <BR> { <BR> if(currentNode.getParent()!=null) <BR> { <BR> currentNode.getParent().setAttribute(Node'Checkrent,true);上一層的父節點 <BR> ParentNode(currentNode.getParent()); <BR> } <BR> } <BR> 🎜 > if(currentNode.getParent()!=null) <BR> { <BR> var checkedCount=0; <BR> var child=currentNode.getParent).🎜> ; i<childNode.length;i ) <BR> { <BR> if(childNode.getAttribute('Checked')) <BR> { <> eckedCount. ; if(checkedCount= =0) <br> { <br> currentNode.getParent().setAttribute('Checked',false); <BR> } <>Chi // //@ //(current)Node 🎜> ChildNode(currentNode.getParent()); <BR> } <BR> } <BR><BR>複製程式碼 程式碼如下: var AllRootNode=new Array(); AllRootNode=TreeView1.getChildren(); AlertNode(AllRootNode); function AlertNode(NodeArray) { else { for(i=0;i cNode=NodeArray; alert(cNode.getAttribute("Text")); if(parseInt(cNode.getChildren().length)!=0) 0) } } }