• 技术文章 >web前端 >html教程

    div+css模拟select下拉框实例代码

    零下一度零下一度2017-06-24 13:08:23原创1813
    <!DOCTYPE html>
    <html >
    <head lang="zh">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>无标题文档</title>
        <script src="lib/jquery-1.11.3.min.js?1.1.11" type="text/javascript"></script>
        <style>
            .mod_select ul{margin:0;padding:0;}
            .mod_select ul:after{
                display: block;
                clear: both;
                visibility: hidden;
                height: 0;
                content: '';
            }
            .mod_select ul li{list-style-type:none;float:left;height:24px;}
            .select_label{color:#982F4D;float:left;line-height:24px;padding-right:10px;font-size:12px;font-weight:700;}
            .select_box{float:left;border:solid 1px #ccc;color:#444;position:relative;cursor:pointer;width:165px;font-size:12px;}
            .selet_open{display:inline-block;border-left:solid 1px #ccc;position:absolute;right:0;top:0;width:30px;height:100%;background:url(xjt.png) no-repeat 10px center;}
            .select_txt{display:inline-block;padding-left:10px;width:135px;line-height:24px;height:24px;cursor:text;overflow:hidden;}
            .option{width:165px;;border:solid 1px #ccc;position:absolute;top:24px;left:-1px;z-index:2;overflow:hidden;display:none;}
            .option a{display:block;height:26px;line-height:26px;text-align:left;padding:0 10px;width:100%;background:#fff;}
            .option a:hover{background:#aaa;}
        </style>
    </head>
    <body>
    <div class="mod_select">
        <ul>
            <li>
                <span class="select_label">sort buy:</span>
                <div class="select_box">
                    <span class="select_txt">1</span><a class="selet_open"><b></b></a>
                    <div class="option">
                        <a>1</a>
                        <a>2</a>
                        <a>3</a>
                    </div>
                </div>
            </li>
        </ul>
        <input type="hidden" id="select_value" />
    </div>
    <script>
        $(function(){
            $(".select_box").click(function(event){
                event.stopPropagation();
                $(this).find(".option").toggle();
                $(this).parent().siblings().find(".option").hide();
            });
            $(document).click(function(event){
                var eo=$(event.target);
                if($(".select_box").is(":visible") && eo.attr("class")!="option" && !eo.parent(".option").length)
                    $('.option').hide();
            });
            /*赋值给文本框*/
            $(".option a").click(function(){
                var value=$(this).text();
                $(this).parent().siblings(".select_txt").text(value);
                $("#select_value").val(value)
            })
        });
    </script>
    </body>
    </html>
    
    运行效果图:


    以上就是div+css模拟select下拉框实例代码的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    上一篇:html实现的动图之小猫笑脸 下一篇:想当Web前端开发工程师你需要会什么?
    20期PHP线上班

    相关文章推荐

    • 【活动】充值PHP中文网VIP即送云服务器• div+CSS浏览器兼容问题整理(IE6.0、IE7.0 ,ie8 , FireFox)_html/css_WEB-ITnose• ajax简单小例子_基于xml的实现• 浏览器得到地址栏的相关信息_html/css_WEB-ITnose• Codeforces Round#263(Div.2)_html/css_WEB-ITnose• bootstrap问题 高手在哪里?_html/css_WEB-ITnose
    1/1

    PHP中文网