The TreeView control the JS control is all selected or canceled

Source: Internet
Author: User

  This article is mainly on the JS control of the TreeView control Select or cancel the sample code is introduced, the need for friends can come to the reference, I hope to help you.

The code is as follows: <script language= "JavaScript" >   /*    function Name: Checknode (CurrentNode), ParentNode ( CurrentNode), Childnode (currentnode)      function function: To implement the TreeView with CheckBox    1, select parent node its child nodes are all selected    2, the selection of all the child nodes, the choice of the parent node will also be canceled      use method: 1, add Checknode in <head></head> Center ( CurrentNode), ParentNode (CurrentNode), Childnode (CurrentNode)      2, *.aspx.cs in Page_Load () Add YourTreeView.Attribute.Add to the event ("Oncheck", "Checknode (Yourtreeview.gettreenode (yourtreeview.clickednodeindex))" )     /      //recursive traverse all sub nodes      function   Checknode (CurrentNode)      {     var   childnode=new   Array ();      var   PARENTN Odechild=new   Array ();      var   ischecked;      Childnode=currentnode.getchildren ();      if (currentnode.getattribute (' checked '))      {     Ischecked=true;     }      Else      {     ischecked=false    &NB Sp }     //parent node processing      if (currentnode.getparent ()!=null)      {   &N Bsp Check processing      if (Currentnode.getattribute (' Checked '))      {     parentnode (CurrentNode);     }      Else     //uncheck the      {     CHILDN Ode (CurrentNode);     }     }      Else      {    //Nothing done &NB sp;   }     //Sub-node processing      if (childnode.length>0)      { & nbsp   for (var   i=0;i<childnode.length;i++)      {     Childnode.setattribute (" Checked ", ischecked);      if (Childnode.getchildren (). Length>0)      {     checknode (childnode);     }     } &N bsp;   }       }     //Recursive selected parent node      function   PARENTN Ode (CurrentNode)      {     if (currentnode.getparent ()!=null)      {      Currentnode.getparent (). setattribute (' Checked ', true);     //Recursive call ParentNode (CurrentNode) to traverse the parent node of the upper level      ParentNode (Currentnode.getparent () );     }     }     //recursive uncheck parent node      function   Childnode ( CurrentNode)      {     if (currentnode.getparent ()!=null)      { & nbsp   var   checkedcount=0;      var   childnode=currentnode.getparent (). GetChildren ();      for   (var   i=0;i<childnode.length;i++)    &NBsp {     if (Childnode.getattribute (' Checked '))      {     checkedcount++; & nbsp;   }     }      if (checkedcount==0)      {   &nbs P Currentnode.getparent (). setattribute (' Checked ', false);     }     //Recursive call Childnode (CurrentNode) to traverse a higher level of the parent node      Childnode ( Currentnode.getparent ());     }     }      </script>     JS recursively traverse all child nodes of a node in the TreeView Copy code code as follows:  var   allrootnode=new   Array ();        Allrootnode=treeview1.getchildren ();        Alertnode (Allrootnode);                function   Alertnode (nodearray)        {& nbsp;        if (parseint (nodearray.length) ==0)            return;      &NBSp   Else          {           for (i=0;i<nodearray.length;i++ )            {             var   cnode  &nbsp ;           Cnode=nodearray;              alert (Cnode.getattribute ("Text"));              if (parseint (Cnode.getchildren (). Length)!=0)        & nbsp       Alertnode (Cnode.getchildren ());                    {        }    &N Bsp  }    
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.