码迷,mamicode.com
首页 > 其他好文 > 详细

下拉菜单的实现

时间:2018-07-10 22:08:12      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:none   meta   doc   lang   style   func   下拉菜单   remove   doctype   

<!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>

 

下拉菜单的实现

标签:none   meta   doc   lang   style   func   下拉菜单   remove   doctype   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!