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);
            }    
  • 相关阅读:
    bzoj1036 [ZJOI2008]树的统计Count(树链剖分)
    poj2348 Euclid's Game
    bzoj3575 [Hnoi2014]道路堵塞
    poj2484 A Funny Game
    bzoj2286 [Sdoi2011]消耗战
    虚树学习笔记
    bzoj4518 [Sdoi2016]征途
    node.js开发环境配置
    js中阻止事件冒泡和浏览器默认行为
    css3 background-clip和background-origin 区别
  • 原文地址:https://www.cnblogs.com/xuwendong/p/7094208.html
Copyright © 2011-2022 走看看