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

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

 

js代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
$("#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 @   一指流砂~  阅读(8829)  评论(2编辑  收藏  举报
点击右上角即可分享
微信分享提示