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);
            }    
  • 相关阅读:
    Swift
    Swift
    Swift
    Swift
    Swift
    Swift
    Swift
    Swift
    Swift
    算法の序列
  • 原文地址:https://www.cnblogs.com/xuwendong/p/7094208.html
Copyright © 2011-2022 走看看