|
- <html>
-
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>及联选择-用于权限选择比较合适</title>
- </head>
-
- <body>
- <ul id="tree">
- <li><input type=checkbox>中国
- <ul>
- <li><input type=checkbox>山东
- <ul>
- <li><input type=checkbox>青岛</li>
- <li><input type=checkbox>枣庄</li>
- </ul>
- </li>
- </ul>
- </li>
- </ul>
- </body>
- <script language="javascript">
-
- var arr = tree.getElementsByTagName('input')
- for(var i=0; i<arr.length; i++){
- var input = arr
- if(input.type = 'checkbox'){
- input.onclick = ClickInput
- }
- }
-
- function ClickInput(){
- var li = this.parentElement;
- var arr = li.getElementsByTagName('input')
- for(var i=0; i<arr.length; i++){
- var input = arr
- if(input.type == 'checkbox'){
- input.checked = this.checked
- }
- }
- var li = li.parentElement.parentElement
-
- while(li.tagName.toLowerCase() == 'li'){
- var input = li.childNodes[0]
- if(input.tagName.toLowerCase() == 'input'){
- input.checked = this.checked
- }
- li = li.parentElement.parentElement
- }
- }
-
- </script>
- </html>
-
复制代码 |
|