账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    jQuery 下拉菜单显示和隐藏
    18
    0

    想做的效果是点击按钮显示下拉菜单,再点击按钮或者其他地方就隐藏菜单,再次点击按钮能显示菜单,谢谢。
    代码:

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
            <style>
                .link{
                    position: relative;
                    padding-left: 50px;
                    padding-top: 100px;
                }
                .link button{
                    width: 180px;
                    height: 30px;
                    background: gray;
                    border: 1px solid transparent;
                    border-radius: 4px;
                    text-align: left;
                    padding-left: 15px;
                    cursor: pointer;
                    color: #333;
                }
                .link button:hover{
                    background-color: #e6e6e6;
                    border-color: #adadad;
                }
                .link button span{
                    display: block;
                    width:0px;
                    height:0px;
                    border-top:10px solid #666;
                    border-left:5px solid transparent;
                    border-right:5px solid transparent;
                    float: right;
                    margin-top: 4px;
                    margin-right: 10px;
                }
                .link ul{
                    position: absolute;
                    display: none;
                    top: 10px;
                    left: 50px;
                    z-index: 1000;
                    float: left;
                    min-width: 160px;
                    padding: 5px 0;
                    margin: 2px 0 0;
                    font-size: 14px;
                    text-align: left;
                    list-style: none;
                    background-color: #fff;
                    -webkit-background-clip: padding-box;
                    background-clip: padding-box;
                    border: 1px solid #ccc;
                    border: 1px solid rgba(0,0,0,.15);
                    border-radius: 4px;
                    -webkit-box-shadow: 0 6px 12px rgba(0,0,0,.175);
                    box-shadow: 0 6px 12px rgba(0,0,0,.175);
                }
                .link ul li{
                    line-height: 24px;
                }
                .link ul li>a{
                    padding-left: 10px;
                    color: #333;
                    width: 80%;
                    display: inline-block;
                }
            </style>
        </head>
        <body>
            <div class="link">
                <button type="button">
                    友情链接
                    <span class="down-triangle"></span>
                </button>
                <ul>
                    <li><a href="#">友情链接</a></li>
                    <li><a href="#">友情链接</a></li>
                    <li><a href="#">友情链接</a></li>
                </ul>
            </div>
            <script type="text/javascript" src="js/jquery-3.3.1.js" ></script>
            <script>
                $(".link button").click(function(){
                    if($(".link ul").css("display")=="none"){
                        $(".link ul").css("display","block");
                    }else{
                        $(".link ul").css("display","none");
                    }
                });
            </script>
        </body>
    </html>
    
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 纸条线 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部