首页 建站教程 WEB前端 正文

自定义select下拉框

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <!--<link rel="stylesheet"&...
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <!--<link rel="stylesheet" href="bootstrap.css"/>-->
    <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    <!--<script src="Jquery-1.11.3.js"></script>-->
    <script src="http://code.jQuery.com/jquery-1.8.0.min.js"></script>
    <style>
        ul,li,ol,li{
            list-style:none;
            margin:0;padding:0;
        }
        a,a:link,a:hover,a:visited {
            text-decoration: none;
            color: #333;
            cursor: pointer;
        }
        .dk_toggle:hover{
            color: #00a2d2;
        }
        .fg-text{
            width:110px;
            float: left;
            line-height: 34px;
            text-align: right;
            padding-right: 5px;
            margin-bottom: 0;
            font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;
            font-size: 13px; font-weight: normal;}
        .fg-input{
            margin-left:110px;
            position: relative;
        }
        .dk_toggle{
            width:100%;
            border: 1px solid #ccc;
            border-radius: 5px;
            display:inline-block;
            font-size:14px;
            color:#333;
            padding:7px 10px;}
        .dk_toggle:after{
            border-top:5px solid #4B4B4B;
            border-right:5px solid transparent;
            border-left: 5px solid transparent;
            content: "";
            position: absolute;
            right:15px; top:45%;
        }
        .dk_option{
            position:absolute;
            top:32px;
            width:100%;
            border: 1px solid #8c8c8c;
            border-bottom-left-radius: 5px;
            border-bottom-right-radius: 5px;
            border-top-color:#ddd;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
            z-index: 100;background: #FFFFFF}
        .dk_option ul li{
            width:100%;
            padding:8px 10px;
        }
        .dk_hover{
            background: #00a2d2
        }
        .hide{
            display: none
        }
    </style>
</head>
<body>
    <div class="form-group col-md-6">
        <label>项目列表:</label>
        <div>
            <a href="#">请选择</a>
            <div class="dk_option hide" >
                <ul>
                    <li>
                        <a href="#">请选择</a>
                    </li>
                    <li>
                        <a href="#">项目一</a>
                    </li>
                    <li>
                        <a href="#">项目二</a>
                    </li>
                    <li>
                        <a href="#">项目三</a>
                    </li>
                    <li>
                        <a href="#">项目四</a>
                    </li>

                </ul>
            </div>
        </div>
    </div>
    <script>
        $(function(){
           $("a,input,button").focus(function(){this.blur()});
           var dk_option = $(".dk_option");
           var dk_toggle = $(".dk_toggle");
            dk_toggle.click(function(event){
                event.preventDefault();
               if(dk_option.hasClass("hide")){
                   dk_option.removeClass("hide");
               }else{
                   dk_option.addClass("hide")
               }
           });
            dk_option.on("mouseover","li",function(){
                $(this).addClass("dk_hover")
                       .siblings("li")
                       .removeClass("dk_hover")
            });
            dk_option.on("click","li",function(){
                dk_toggle.html( $(this).children("a").html())
                              .next(".dk_option")
                              .addClass("hide");
            })
       });
    </script>
</body>
</html>


打赏
海报

本文由优美主题原创或收集发布

转载请注明本文地址:https://www.umtheme.com/web/35.html

相关推荐

CSS心形缠绕转动效果

CSS心形缠绕转动效果

CSS心形缠绕转动效果是一种有趣的动画效果,能够给网页带来浪漫而动感的氛围。这个效果将一个心形图案无限旋转,并且同时绕着一个中心点缠绕旋...
WEB前端 2023.09.13 0 2348
制作h5常用的css3动画效果

制作h5常用的css3动画效果

css3提供了许多强大的特效,可以用来实现各种各样的效果,下面是我总结的一些常用的css3效果,有需要的可以直接引用:1.悬浮时放大:.one{transition:All 0.4s&nb...
WEB前端 2023.09.13 0 2201
发布评论

感谢您的支持