首页 > 代码库 > TreeView控件点击父节点同时选择子节点JS脚本
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.length17 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>
TreeView控件点击父节点同时选择子节点JS脚本
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。