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>

  • 相关阅读:
    ubuntu搭建php开发环境记录
    zz-什么是网关,路由,dns,通俗讲解
    如何设置root用户密码
    zz三台centos7虚拟机设置相互免密码登录
    go之闭包及其应用
    网络是怎样连接的
    进程间通信方式探索
    现代操作系统——操作系统概念
    现代操作系统——硬件_IO设备——设备控制器和设备本身
    simotion byte/word ASCII码转换为字符、字符串
  • 原文地址:https://www.cnblogs.com/cjmtt/p/2920728.html
Copyright © 2011-2022 走看看