jQuery jquery在jquery ui自动完成上捕获点击事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19440428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jquery catching click event on jquery ui autocomplete
提问by tomexsans
i have been trying to figure this out lately but i can't
我最近一直在努力解决这个问题,但我不能
the problem is that i have an input
field with type text
that i need to get the current input data when the values from the autocomplete are selected. Note i am using jQuery UI autocomplete.
问题是我有一个input
字段,其中类型text
是在选择自动完成的值时需要获取当前输入数据。请注意,我正在使用 jQuery UI 自动完成功能。
i can catch the keyup
event but when a user uses clicks on the autocomplete values. jQuery does not fire the change
event handler, i tried using every event handler there is but to no avail.
我可以捕获该keyup
事件,但是当用户单击自动完成值时。jQuery 不触发change
事件处理程序,我尝试使用每个事件处理程序,但无济于事。
i think it cannot catch a DOM based manipulation of an element? i'm not sure. here is a fiddle
我认为它无法捕获基于 DOM 的元素操作?我不知道。这是一把 小提琴
回答by Tats_innit
Like thishttp://jsfiddle.net/PUpRr/
select
options should do the trick.
select
选项应该可以解决问题。
Options/events/methods API documentation: http://api.jqueryui.com/autocomplete/
选项/事件/方法 API 文档:http: //api.jqueryui.com/autocomplete/
Hope this fits the needs :)
希望这符合需求 :)
Sample code
示例代码
$("#to").autocomplete({
source: function (request, response) {
var friendsArray = [];
friendsArray = [{
"id": 1,
"name": "hulk",
"value": "hulk"
}, {
"id": 2,
"name": "ironman",
"value": "ironman"
}, {
"id": 3,
"name": "Foobar",
"value": "Foobar"
}];
response(friendsArray);
return;
},
select: function (e, ui) {
alert("selected!");
},
change: function (e, ui) {
alert("changed!");
}
});