zoukankan      html  css  js  c++  java
  • 模糊查询输入框

    css部分:

    <style type="text/css">
        body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td{
            margin:0;
            padding:0;
        }
    
        .nice-select input{
            outline: none;
            cursor: pointer;
            width: 14em;
            height: 1.8em;
            font-size: 1em;
            border: 1px solid #000;
            background: url(image/icon.png) no-repeat scroll right center transparent;
            background-position: 96% 50%;
            padding: 0 10px;
            -webkit-border-radius: .3em;
            -moz-border-radius: .3em;
            border-radius: .3em;
            position: absolute;
            line-height: 1.8em;
        }
    
        ul{
            list-style: none;
        }
    
        .nice-select{
            position: relative;
            width: 14em;
           margin: 20px;
            box-shadow: 0 3px 5px #999;
            -webkit-border-radius: .3em;
            -moz-border-radius: .3em;
            border-radius: .3em;
        }
    
        .nice-select ul{
            display: none;
            border: 1px solid #d5d5d5;
            width: 13.9em;
            position: absolute;
            top: 1.8em;
            overflow: hidden;
            background-color: #fff;
            max-height: 150px;
            overflow-y: auto;
            border-top: 0;
            z-index: 10001;
        }
    
        .nice-select ul li{
            height: 30px;
            line-height: 2em;
            overflow: hidden;
            padding: 0 10px;
            cursor: pointer;
            border-top: 1px solid #d5d5d5;
        }
    
        .nice-select ul li.on{background-color: #e0e0e0;}
    
    </style>

    html部分:

    <div class="nice-select">
        <input id="customerId" type="text" oninput="searchList(this.value)">
        <ul>
            <li>Java--我的最爱</li>
            <li>PHP--很棒的wo</li>
            <li>HTML--简单</li>
            <li>jQuery--有点难</li>
            <li>Android--安卓</li>
            <li>C--不会</li>
            <li>C++--更不会</li>
            <li>Struts--懂哦</li>
            <li>hibernate--已经不怎么懂</li>
            <li>spring--懂哦</li>
            <li>0123456789--10</li>
        </ul>
    </div>

    js部分:(此处需要引入jquery.js)

    <script type="text/javascript">
        $(function(){
            $(".nice-select").click(function(e){
                $(this).find("ul").show();
                e.stopPropagation();
            });
    
            $(".nice-select ul li").hover(function(e){
                $(this).toggleClass("on");
                e.stopPropagation();
            });
    
            $(".nice-select ul li").click(function(e){
                var val = $(this).text();
                val = val.substring(0, val.indexOf('--'));
                $(".nice-select").find("input").val(val);
                $(".nice-select").find("ul").hide();
                e.stopPropagation();
            });
    
            $(document).click(function(){
                $(".nice-select").find("ul").hide();
            });
        });
    
        function searchList(strValue) {
            var count = 0;
            if (strValue != "") {
                $(".nice-select ul li").each(function(i) {
                    var contentValue = $(this).text();
                    if ((contentValue.indexOf(strValue.toLowerCase()) < 0)
                            && (contentValue.indexOf(strValue.toUpperCase()) < 0)) {
                        $(this).css("display", "none");
                        count++;
                    } else {
                        $(this).css("display", "block");
                    }
                    if (count == (i + 1)) {
                        $(".nice-select").find("ul").hide();
                    } else {
                        $(".nice-select").find("ul").show();
                    }
                });
            } else {
                $(".nice-select ul li").each(function(i) {
                    $(this).css("display", "block");
                });
            }
        }
    
    </script>
  • 相关阅读:
    Linux下mysql使用systemctl restart mysqld命令失败
    Linux环境下mysql报错:bash: mysql: command not found 的解决方法
    Linux查看mysql是否启动的命令
    启动MySQL5.7时报错:initialize specified but the data directory has files in it. Aborting.
    ARM64架构下面安装mysql5.7.22
    Python3.6打开EAIDK-610开发板(计算机通用)摄像头拍照并保存
    Python的几种主动结束程序方式
    aarch64架构下安装tensorflow详细过程
    python代码在linux终端中执行报错:Unable to init server: Could not connect: Connection refused
    red hat 报错:apt-get:找不到命令
  • 原文地址:https://www.cnblogs.com/shanhaihong/p/5691240.html
Copyright © 2011-2022 走看看