zoukankan      html  css  js  c++  java
  • 模糊查询的下拉框

    css部分:

    <style type="text/css">
        #demo-wrap{position:relative;margin:20px;width:260px;overflow:hidden;border:1px solid #DDD;}
        #demo-wrap .product-head p{font-size:14px;font-family:Arial,Helvetica,sans-serif;margin:5px 3px 5px;padding:0 0 5px;}
        #demo-wrap .product-head{font-size:12px;padding:8px 4px;background-color:#F1F1F1;}
        #demo-wrap .filterform{border:1px solid #999;border-radius:15px;padding:4px 12px;background-color:#fff;}
        #demo-wrap .filterform input{font-size:12px;padding:0;border:0;outline:none;}
        ul#demo-list li{padding:8px;list-style:none;border-top:1px solid #ccc;border-bottom:1px solid #fff;}
        ul#demo-list li a{color:#000;font-family:Arial,Helvetica,sans-serif;font-size:11px;text-decoration:none;}
        ul#demo-list{margin:0;padding:0;}
        .clear{clear:both;}
    </style>

    html部分:

    <div id="demo-wrap">
        <div class="product-head">
            <p>搜索列表内容:</p>
            <div id="form">
    
            </div>
        </div>
        <ul id="demo-list">
            <li><a href="http://www.17sucai.com/">张三</a></li>
            <li><a href="http://www.17sucai.com/">李四</a></li>
            <li><a href="http://www.17sucai.com/">jQuery</a></li>
            <li><a href="http://www.17sucai.com/">Apple</a></li>
            <li><a href="http://www.17sucai.com/">AAAAAAA</a></li>
            <li><a href="http://www.17sucai.com/">BBBBBBB</a></li>
            <li><a href="http://www.17sucai.com/">BCCCCCCC</a></li>
            <li><a href="http://www.17sucai.com/">CCCCCCC</a></li>
            <li><a href="http://www.17sucai.com/">CDDDDD</a></li>
            <li><a href="http://www.17sucai.com/">CAAAAA</a></li>
            <li><a href="http://www.17sucai.com/">EEDDDDDD</a></li>
            <li><a href="http://www.17sucai.com/">Feeee</a></li>
            <li><a href="http://www.17sucai.com/">ACCCCCCC</a></li>
            <li><a href="http://www.17sucai.com/">FEEEEEEEE</a></li>
            <li><a href="http://www.17sucai.com/">jJack</a></li>
        </ul>
    </div>

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

    <script type="text/javascript">
        (function($) {
            $.expr[":"].Contains = function(a, i, m) {
                return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
            };
            function filterList(header, list) {
                //@header 头部元素
                //@list 无需列表
                //创建一个搜素表单
                var form = $("<form>").attr({
                    "class":"filterform",
                    action:"#"
                }), input = $("<input>").attr({
                    "class":"filterinput",
                    type:"text"
                });
                $(form).append(input).appendTo(header);
                $(input).change(function() {
                    var filter = $(this).val();
                    if (filter) {
                        $matches = $(list).find("a:Contains(" + filter + ")").parent();
                        $("li", list).not($matches).slideUp();
                        $matches.slideDown();
                    } else {
                        $(list).find("li").slideDown();
                    }
                    return false;
                }).keyup(function() {
                    $(this).change();
                });
            }
            $(function() {
                filterList($("#form"), $("#demo-list"));
            });
        })(jQuery);
    </script>
  • 相关阅读:
    CSS行高——line-height
    非替换元素和替换元素
    7-7 jmu_python_是否是数 (10 分)
    7-8 jmu-python-从列表中删除元素 (15 分)
    7-6 jmu_python_最大公约数&最小公倍数 (10 分)
    7-5 jmu-python-分段函数1 (10 分)
    7-4 jmu-python-判断是否构成三角形 (10 分)
    7-3 jmu-python-回文数判断(5位数字) (10 分)
    7-2 jmu-python-九九乘法表(矩形) (10 分)
    7-1 jmu-python-汇率兑换 (10 分)
  • 原文地址:https://www.cnblogs.com/shanhaihong/p/5691234.html
Copyright © 2011-2022 走看看