JQuery autocomplete获得焦点触发弹出下拉框

需求:autocomplete控件,当点击获得焦点的时候也要弹出下拉列表(autocomplete默认是输入之后才会跟随出下拉列表),下面直接贴代码。

 

js代码:

$("#customerName").autocomplete({
            minLength: 0,
            source: function (request, response) {
                var customerName = $("#customerName").val();
                $.ajax({
                    url: "/api/pmstransaction/getcustomerinfo",
                    dataType: "json",
                    data: {
                        customerName: customerName
                    },
                    success: function (data) {
                        response(data.Data);
                    }
                });
            },
            focus: function (event, ui) {
                $("#customerName").val(ui.item.CustomerName);
                return false;
            },
            select: function (event, ui) {
                module.viewModel.customerInfo.CustomerName(ui.item.CustomerName);
                module.viewModel.customerInfo.CustomerTaxCode(ui.item.CustomerTaxCode);
                module.viewModel.customerInfo.CustomerAddressPhone(ui.item.CustomerAddressPhone);
                module.viewModel.customerInfo.CustomerBankAccount(ui.item.CustomerBankAccount);
                return false;
            }
        }).focus(function () {
            $(this).autocomplete("search");
        }).autocomplete("instance")._renderItem = function (ul, item) {
            return $("<li>")
                .append("<div>" + item.CustomerName + "</div>")
                .appendTo(ul);
        }

  

  重点代码

focus(function () {
$(this).autocomplete("search");
})

posted @ 2017-03-02 10:56  一指流砂~  阅读(8822)  评论(2编辑  收藏  举报