123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- }
- ul {
- list-style: none;
- }
- h2 {
- width: 300px;
- height: 50px;
- background: black;
- color: white;
- }
- ul{
- display: none;
- }
- </style>
- </head>
- <body>
- <div id="container">
- <h2>管理区</h2>
- <ul>
- <li>111</li>
- <li>111</li>
- <li>111</li>
- </ul>
- <h2>交流区</h2>
- <ul>
- <li>456</li>
- <li>456</li>
- <li>456</li>
- </ul>
- </div>
- <script>
- var h2 = document.getElementsByTagName('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(elem){
- do{
- elem = elem.nextSibling
- } while(elem.nodeType != 1)
- return elem
- }
- </script>
- </body>
- </html>
|