DOM之左侧菜单栏

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>

        .hide{
            display:none;
        }

        .item .header{
            height:35px;
            background:grey;
            color: orange;
            line-height: 35px;
        }


    </style>

</head>
<body>
    <div style="height:48px"></div>

    <div style="width: 300px;">
        <div class="item">
            <div id="i1" class="header" onclick="ChangeMenu(‘i1‘)">菜单一</div>
            <div class="content">
                <div>内容一</div>
                <div>内容二</div>
                <div>内容三</div>
            </div>
        </div>
        <div class="item">
            <div id="i2" class="header" onclick="ChangeMenu(‘i2‘)">菜单2</div>
            <div class="content hide">
                <div>内容1</div>
                <div>内容2</div>
                <div>内容3</div>
            </div>
        </div>
        <div class="item">
            <div id="i3" class="header" onclick="ChangeMenu(‘i3‘)">菜单3</div>
            <div class="content hide">
                <div>内容1</div>
                <div>内容2</div>
                <div>内容3</div>
            </div>
        </div>
    </div>

    <script>
        function ChangeMenu(nid) {
            var current_header = document.getElementById(nid);
            var item_list = current_header.parentElement.parentElement.children;
            for(var i=0;i<item_list.length;i++){
                current_item = item_list[i];
                current_item.children[1].classList.add(‘hide‘);
            }
            //当前的兄弟的下一个div去掉hide
            current_header.nextElementSibling.classList.remove(‘hide‘);
        }



    </script>


</body>
</html>

DOM之左侧菜单栏

上一篇:msyql调优方式


下一篇:在bochs中运行linux-0.11系统(环境搭建)