首页 建站教程 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>


打赏
海报

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

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

相关推荐

如何在html页面中通过css隐藏元素

在平常的页面布局中,我们经常会遇到将某个模块隐藏,而实现不同的页面布局或js交互效果,尤其是在响应式布局中比较常见,下面我们整理了一些关于实现隐藏页面元素的多种方法以及各种方法不同的特点(如:是否占据...

WEB前端 2020.09.18 0 34

web前端写html页面div+css命名规范

web前端写html页面div+css命名规范

使用良好的CSS书写规范来写CSS代码,既能最大化优化前端代码,提升代码阅读体验,更重要的是为以后维护带来方便。常用的CSS命名一般由小...

WEB前端 2020.09.08 0 88

给网页增加WOW插件滚动触发css动效

随着浏览器的兼容性增强,css3动画特效运用也越来越广,通过css3动画库加js可以实现很多炫酷的效果。比如在滚动页面时会触发展示各式各样的动画效果,通过设置调整可以改变动画的风格、延迟、偏移量等。优...

WEB前端 2018.07.04 0 3672

发布评论

ainiaobaibaibaibaobaobeishangbishibizuichiguachijingchongjingdahaqiandaliandangaodw_dogedw_erhadw_miaodw_tuzidw_xiongmaodw_zhutouganbeigeiliguiguolaiguzhanghahahahashoushihaixiuhanheixianhenghorse2huaixiaohuatonghuaxinhufenjiayoujiyankeaikeliankouzhaokukuloukunkuxiaolandelinileimuliwulxhainiolxhlikelxhqiuguanzhulxhtouxiaolxhwahahalxhzanningwennonuokpinganqianqiaoqinqinquantouruoshayanshengbingshiwangshuaishuijiaosikaostar0star2star3taikaixintanshoutianpingtouxiaotuwabiweifengweiquweiwuweixiaowenhaowoshouwuxiangjixianhuaxiaoerbuyuxiaokuxiaoxinxinxinxinsuixixixuyeyinxianyinyueyouhenghengyuebingyueliangyunzanzhajizhongguozanzhoumazhuakuangzuohenghengzuoyi

感谢您的支持