TreeView控件点击父节点同时选择子节点JS脚本

 1  <script language="javascript" type="text/javascript">
 2         function client_OnTreeNodeChecked() {
 3             var obj = window.event.srcElement;
 4             var treeNodeFound = false;
 5             var checkedState;
 6             if (obj.tagName == "INPUT" && obj.type == "checkbox") {
 7                 var treeNode = obj;
 8                 checkedState = treeNode.checked;
 9                 do {
10                     obj = obj.parentElement;
11                 }
12                 while (obj.tagName != "TABLE")
13                 var parentTreeLevel = obj.rows[0].cells.length;
14                 var parentTreeNode = obj.rows[0].cells[0];
15                 var tables = obj.parentElement.getElementsByTagName("TABLE");
16                 var numTables = tables.length
17                 if (numTables >= 1) {
18                     for (i = 0; i < numTables; i++) {
19                         if (tables[i] == obj) {
20                             treeNodeFound = true;
21                             i++;
22                             if (i == numTables) {
23                                 return;
24                             }
25                         }
26                         if (treeNodeFound == true) {
27                             var childTreeLevel = tables[i].rows[0].cells.length;
28                             if (childTreeLevel > parentTreeLevel) {
29                                 var cell = tables[i].rows[0].cells[childTreeLevel - 1];
30                                 var inputs = cell.getElementsByTagName("INPUT");
31                                 if (inputs.length > 0) {
32                                     inputs[0].checked = checkedState;
33                                 }
34                             }
35                             else { return; }
36                         }
37                     }
38                 }
39             }
40         }
41     </script>
    控件上调用:
        <asp:TreeView ID="TreeView1" runat="server" onclick="client_OnTreeNodeChecked();">
        </asp:TreeView>

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。