js下拉菜单

<!DOCTYPE HTML>
<html>
    <head>
        <title>表下拉菜单</title>
        <mate charset="utf-8" />
        <style type="text/css">
        *{ padding: 0px; margin: 0px; text-align: center; }
        .bpp1{ width: 80px; margin: 30px auto; }
        .all_dd dd{ display: none; }
        .bpp1 dt, .all_dd dd{ width: 80px; height: 35px; margin-bottom: 1px; line-height: 35px;  border-radius: 5px 5px 5px 5px; color: #ffffff; }
        .bpp1 dt{ background: #12ebb5; cursor: pointer; }
        .all_dd dd{ float: top; background: chartreuse; cursor: pointer; }
        .all_dd dd.current, .all_dd dd.active{ background: rgb(114, 233, 2); color: #ffffff; }
        </style>
        <script src="../../jquery-3.4.1.min.js"></script>
    </head>
    <body>
        <div class="bpp1">
            <dl>
                <dt>游客</dt>
                <div class="all_dd"></div>
            </dl>
        </div>

        <script type="text/javascript">
            var roles = ["站长", "管理员", "用户", "游客", "坏蛋"];
            var judge = false;
            $(document).ready(function(){
                for(var i in roles){
                    $(".all_dd").append("<dd>" + roles[i] + "</dd>");
                }
                $(".bpp1 dt").click(function(){
                    if(!judge){
                        $(".all_dd dd").css("display", "block");
                    }else{
                        $(".all_dd dd").css("display", "none");
                    }
                    judge = !judge;
                    $(".all_dd dd").hover(function(){
                        $(this).addClass("current");
                    },function(){
                        $(this).removeClass("current");
                    });
                    $(".all_dd dd").click(function(){
                        $(".bpp1 dt").text($(this).text());
                        $(this).removeClass("current");
                        for(var i in roles){
                            $(".all_dd dd").removeClass("active").css("display", "none");
                        }
                        $(this).addClass("active");
                        judge = false;
                    });
                });
                
            });
        </script>
    </body>
</html>

                                     效果图:

                                                          

                                                         

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值