• javascript 左侧菜单


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            .hide{
                display: none;
            }
            .item .header{
                height: 35px;
                background-color: #2459a2;
                color: white;
                line-height: 35px; /*放置垂直*/
    
            }
        </style>
    </head>
    <body>
        <div style="height: 48px"></div>
    
        <div style=" 300px">
            <div class="item">
                <div id='i1' class="header" onclick="ChangeMenu('i1')">菜单一</div>
                <div class="content">
                    <div>内容1</div>
                    <div>内容1</div>
                    <div>内容1</div>
                </div>
            </div>
            <div class="item">
                <div id = 'i2' class="header" onclick="ChangeMenu('i2')">菜单二</div>
                <div class="content">
                    <div>内容2</div>
                    <div>内容2</div>
                    <div>内容2</div>
                </div>
            </div>
            <div class="item">
                <div id = 'i3' class="header" onclick="ChangeMenu('i3')">菜单三</div>
                <div class="content">
                    <div>内容3</div>
                    <div>内容3</div>
                    <div>内容3</div>
                </div>
            </div>
    
        </div>
    
        <!--修改菜单功能-->
        <script>
            function ChangeMenu(mid) {
                var current_header = document.getElementById(mid); //当前头部
                console.log(current_header);
                var current_base_header = current_header.parentElement.parentElement
                console.log(current_base_header);
                var current_list = current_base_header.children;
                for(var i=0;i<current_list.length;i++){
                    var current_item = current_list[i];
                    current_item.children[1].classList.add("hide");
                }
                current_header.nextElementSibling.classList.remove('hide')
            }
        </script>
    </body>
    </html>
  • 相关阅读:
    细节回顾 p标签的嵌套问题
    面向对象编程
    深浅拷贝
    数据交互 jsonp插件
    数据交互 跨域问题
    数据交互 axios
    数据交互 jQuery ajax
    数据交互 后端代码
    数据交互 http请求 xhr
    Windows安装Node.js报错:2503、2502的解决方法
  • 原文地址:https://www.cnblogs.com/Liang-jc/p/9032087.html
Copyright © 2020-2023  润新知