首页 > 其他 > 详细

下拉菜单的实现

时间:2018-07-10 22:03:52      阅读:194      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .hide{
            display: none;
        }
        .item .header{
            height: 35px;
            background-color: #f25022;
            color: white;
            line-height: 35px;
        }
    </style>
</head>
<body>
    <div style="height: 48px"></div>
    <div style="width: 300px">
        <div class="item">
            <div class="header" onclick="ChangeMenu(this)">菜单1</div>
            <div class="content">
                <div>内容1</div>
                <div>内容1</div>
            </div>
        </div>
        <div class="item">
            <div  class="header" onclick="ChangeMenu(this)">菜单2</div>
            <div class="content hide">
                <div>内容2</div>
                <div>内容2</div>
            </div>
        </div>
        <div class="item">
            <div  class="header" onclick="ChangeMenu(this)">菜单3</div>
            <div class="content hide">
                <div>内容3</div>
                <div>内容3</div>
            </div>
        </div>
        <div class="item">
            <div  class="header" onclick="ChangeMenu(this)">菜单4</div>
            <div class="content hide">
                <div>内容4</div>
                <div>内容4</div>
            </div>
        </div>
    </div>
    <script>
        function ChangeMenu(ths){
            current_head = ths;
            var all_text =current_head.parentElement.parentElement;
            children_text = all_text.children;
            for(var i=0; i<children_text.length; i++){
                current_text = children_text[i];

               current_text.children[1].classList.add(hide)
            }

            current_head.nextElementSibling.classList.remove(hide)



        }
    </script>
</body>
</html>

 

下拉菜单的实现

原文:https://www.cnblogs.com/my-love-is-python/p/9291646.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!