zoukankan      html  css  js  c++  java
  • js autocomplete输入延迟触发执行事件

    需求:延迟查询,autocomplete延迟触发执行事件。当有下一个事件开始时,本次事件中断。目的是为了防止调用服务器过于频繁。

            var timeout = 0;//延时处理
            $("#customerName").autocomplete({
                minLength: 0,
                source: function (request, response) {
                    clearTimeout(timeout);
                    console.log(timeout);
                    var customerName = $("#customerName").val();
                    var cutomerToken = $("#cutomerToken").val();
                    timeout = setTimeout(function () {
                        console.log("run");
                        $.ajax({
                            url: "api/pmstransaction/getcustomerbybigdata",
                            dataType: "json",
                            data: {
                                customerName: customerName,
                                token: cutomerToken
                            },
                            success: function (data) {
                                response(data.Data);
                            }
                        });
                    }, 800);
                },
                focus: function (event, ui) {
                    $("#customerName").val(ui.item.Name);
                    return false;
                },
                select: function (event, ui) {
                    module.viewModel.customerInfo.CustomerName(ui.item.Name);
                    module.viewModel.customerInfo.CustomerTaxCode(ui.item.TaxCode);
                    module.viewModel.customerInfo.CustomerAddressPhone(ui.item.AddressPhone);
                    module.viewModel.customerInfo.CustomerBankAccount(ui.item.BankAccount);
    );
                    return false;
                }
            }).autocomplete("instance")._renderItem = function (ul, item) {
                return $("<li>")
                    .append("<div>" + item.Name + "</div>")
                    .appendTo(ul);
            }    
  • 相关阅读:
    Ubuntu系统下的实用软件推荐
    上传项目到GitHub
    eclipse+fileSyncPlugin+svn+jenkins+tomcat
    js,jq获取元素位置属性及兼容性写法
    清除浮动的几种方法
    sub,dl,dt,排版,横向滚动条,浮动元素居中,box-sizing
    a里面不能嵌套a
    随笔
    自适应屏幕轮播图详解
    tip
  • 原文地址:https://www.cnblogs.com/xuwendong/p/7094208.html
Copyright © 2011-2022 走看看