zoukankan      html  css  js  c++  java
  • aotocomplete1

    <script type="text/javascript">
            $(function () {
                $("#txtSearch").autocomplete({
                    minLength: 1, // 设置搜索的关键字最小长度
                    // 设置自动完成列表的函数,函数包括两个参数,requset和response
                    source: function (request, response) {
                        $.ajax({
                            type: "POST",
                            // 通过request.term可以获得文本框内容
                            url: "Handler1.ashx?keyword=" + encodeURIComponent(request.term),
                            contentType: "application/json; charset=gb2312",
                            dataType: "json",
                            success: function (data) {
                                // jQuery.map(array, callback) :将一个数组中的元素转换到另一个数组中。
                                //  下面就是把数组["value1", "value2",...]转换为[{value:"value1"}, {value:"value2"},...]
                                response($.map(data, function (item) {
                                    return { value: item };
                                }));
                            },
                            error: function () {
                                alert("ajax请求失败");
                            }
                        });
                    }
                });
            });
        </script>

  • 相关阅读:
    [Redis-CentOS7]Redis设置连接密码(九)
    [Redis-CentOS7]Redis数据持久化(八)
    PAT Advanced 1101 Quick Sort (25分)
    PAT Advanced 1043 Is It a Binary Search Tree (25分)
    HTTP协议
    PAT Advanced 1031 Hello World for U (20分)
    自然码双拼快速记忆方案
    macOS 原生输入法设置自然码
    PAT Advanced 1086 Tree Traversals Again (25分)
    PAT Advanced 1050 String Subtraction (20分)
  • 原文地址:https://www.cnblogs.com/cjmtt/p/2920728.html
Copyright © 2011-2022 走看看