autocomplete()???

来源:2-6 搜索插件——autocomplete

web_東

2018-04-21 03:43

 <!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="utf-8">
    <title>搜索插件</title>
    <style type="text/css">
        #divtest
        {
            width: 282px;
        }
        #divtest .title
        {
            padding: 8px;
            background-color: Blue;
            color: #fff;
            height: 23px;
            line-height: 23px;
            font-size: 15px;
            font-weight: bold;
        }
        #divtest .content
        {
            padding: 8px 0px;
            background-color: #fff;
            font-size: 13px;
        }
        #divtest .content .tip
        {
            text-align:center;
            border:solid 1px #ccc;
            background-color:#eee;
            margin:20px 0px;
            padding:8px;
            display:none;
        }
        .fl
        {
            float: left;
        }
        .fr
        {
            float: right;
        }



    </style>
    <link href="spacer.gifhttp://www.imooc.com/data/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
    <script src="../js/jquery.min.js"></script>
    <script src="../js/jquery.autocompleter.min.js"></script>
    <script type="text/javascript" src="../js/jquery.autocompleter.js"></script>
    <script src="../js/main.js"></script>
</head>

<body>
<div id="divtest">
    <div class="title">
        <span class="fl">搜索插件</span>
    </div>
    <div class="content">
        <span class="fl">用户名</span><br />
        <input id="txtSearch" name="txtSearch" type="text" />
        <div class="tip">
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        var arrUserName = ["王五", "刘明", "李小四", "刘促明", "李渊", "张小三", "王小明"];
        $("#txtSearch").autocomplete(arrUserName,{
            minChars: 0, //双击空白文本框时显示全部提示数据
            formatItem: function (data, i, total) {
                return "<I>" + data[0] + "</I>"; //改变匹配数据显示的格式
            },
            formatMatch: function (data, i, total) {
                return data[0];
            },
            formatResult: function (data) {
                return data[0];
            }
        }).result(SearchCallback);
        function SearchCallback(event, data, formatted) {
            $(".tip").show().html("您的选择是:" + (!data ? "空" : formatted));
        }
    });
</script>
</body>
</html> 

写回答 关注

1回答

  • 麓鹿不迷路
    2018-06-05 21:47:08

    yeah!you are right!

    amazing!

    we are family!

jQuery基础(五)一Ajax应用与常用插件

如何用jquery实现ajax应用,加入学习,有效提高前端开发速度

69100 学习 · 400 问题

查看课程

相似问题