123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <!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>
- h2 {
- padding: 30px 40px;
- color: #ff0;
- background: #f00;
- margin-top: 30px;
- }
- ul {
- display: none;
- }
- ol {
- display: none;
- }
- </style>
- </head>
- <body>
- <h2>管理区</h2>
- <ul>
- <li>aaaa</li>
- <li>aaaa</li>
- <li>aaaa</li>
- </ul>
- <h2>交流区</h2>
- <ol>
- <li>bbb</li>
- <li>bbb</li>
- <li>bbb</li>
- </ol>
- <script>
- var h2 = document.querySelectorAll("h2");
- console.log(h2)
- for(var i =0;i<h2.length;i++){
- h2[i].onclick = function() {
- var ul1 = next(this);
- console.log(ul1);
- if(ul1.style.display == 'block') {
- ul1.style.display = 'none';
- } else {
- ul1.style.display = 'block';
- }
- }
- }
- function next(ele) {
- do {
- ele = ele.nextElementSibling;
- }while(ele.nodeType != 1)
- return ele;
- }
- </script>
- </body>
- </html>
|