jQuery的自动完成功能获得所选项目的文本

问题描述:

我想知道如何抓住jQuery的自动完成所选项目的文本值。

I am wondering how to grab the selected item's text value on jquery autocomplete.

我已经初始化的jQuery如下:

I have initialised jquery as following :

$(document).ready(function (){
    $("input#autocomplete").autocomplete({
        source: postcodelist,
        select: function (event, ui) {
            AutoCompleteSelectHandler(event, ui)
        }
    });
});

和我创建了一个函数功能AutoCompleteSelectHandler(事件,UI){}

And I have created a function function AutoCompleteSelectHandler(event, ui) { }.

在这个函数中我想一些额外的处理将数据提供给正确的文本框,但我无法弄清楚如何抓住所选项目的文本值。

Inside this function I want to some extra handling to feed data into correct textboxes but I can't figure out how to grab the text value of the selected item.

我google了一下,并试图例子,但我似乎无法得到它的工作。

I did google a bit and tried examples but I can't seem to get it working.

任何帮助将非常AP preciated。

Any help will be much appreciated.

感谢了很多进步。

UI 参数有一个项目属性与所选文本

The ui parameter has an item property with the selected text

function AutoCompleteSelectHandler(event, ui)
{               
    var selectedObj = ui.item;              
    alert(selectedObj.value);
}

来源:http://jqueryui.com/demos/autocomplete/#event-select去标签事件,然后事件选择

source: http://jqueryui.com/demos/autocomplete/#event-select go to tab "Events" and then event "Select"