jQuery自动完成关闭需要获取值

时间:2016-03-28 10:08:22

标签: jquery

$(".autocomplete").autocomplete({
    minLength: 2,
    selectFirst: true,
    autoFocus: true,
    source:
        function (request, response) {
            $.ajax({
                type: "POST",
                url: "/airports.ashx?q=" + request.term,
                contentType: "application/json; charset=utf-8",
                async: false,
                dataType: "json",
                success: function (data) {
                    response($.map(data, function (item) {
                        return { value: item }
                    }));
                },
                error: function (data) {
                    alert("An unexpected error has occurred during processing.");
                }
            });
        }, select: function (event) {
        }
       , close: function (event, ui) {
           $("#txtfrom").val(ui.item.value);
       }
}); 

1 个答案:

答案 0 :(得分:0)

将此值放入'选择'事件,它不会在' close'

中提供

试试这个.......

, select: function (event) {
$("#txtfrom").val(ui.item.value);
        }
       , close: function (event, ui) {

       }

如果你想要在关闭然后使用那样....... 在自动完成之外声明值

var value ='';

, select: function (event) {
value=ui.item.value;
        }
       , close: function (event, ui) {
           $("#txtfrom").val(value);
       }