123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- list-style: none;
- text-decoration: none;
- box-sizing: border-box;
- }
- ul {
- display: none;
- }
- </style>
- </head>
- <body>
- <h2>管理区</h2>
- <ul id="manager">
- <li>1</li>
- <li>2</li>
- <li>3</li>
- <li>4</li>
- </ul>
- <h2>内容区</h2>
- <ul id="main">
- <li>a</li>
- <li>b</li>
- <li>c</li>
- <li>d</li>
- </ul>
- <script>
- var h2 = document.getElementsByTagName("h2");
- console.log(h2)
- for(var i=0; i<h2.length;i++) {
- h2[i].onclick = function() {
- // console.log(this.nextSibling);
- var ul1 = next(this)
- console.log(ul1);
- // ul1.style.display = 'block'
- if(ul1.style.display == 'none') {
- ul1.style.display = 'block'
- } else {
- ul1.style.display = 'none'
- }
- }
- }
- function next(ele) {
- do {
- ele = ele.nextSibling;
- }while(ele.nodeType != 1)
- return ele;
- }
- </script>
- </body>
- </html>
|