嗨我遇到了更改事件的问题。 By documntation should be object ui.itemJquery UI自动完成事件更改
选择一个项目后; ui.item引用所选项目。总是在关闭事件后触发。
但是当我尝试它ui.item是未定义:(我想取消设置s_town_id时自动完成输入不匹配从脚本数据。
<input id="s_town" type="text" name="s_town" />
<input type="text" id="s_town_id" name="s_town_id" />
$(function() {
$("#s_town").autocomplete({
source: function(request, response) {
$.ajax({
url: "/_system/_ajax/uiautocomplete.php",
dataType: "json",
data: {
name: "s_town",
term: request.term
},
success: function(data) {
response($.map(data, function(item) {
return {
label: item.whisper_name+ " [" + item.zip_code + "/" + item.lup_state + "]",
value: item.whisper_name,
id: item.whisper_id,
zip_code: item.zip_code,
lup_state: item.lup_state,
stateid: item.stateid
}
}))
}
})
},
minLength: 2,
select: function(event, ui) {
$("#s_town_id").val(ui.item.id);
},
change: function(event, ui)
{
// ui.item is undefined :(where is the problem?
$("#s_town_id").val(ui.item.id);
}
});
});
嗨Stenly,我有完全相同的问题,并不得不使用相同的解决方法。你能找到更好的解决方案吗? – blacktie24 2011-04-02 22:49:11
hmm意识到问题在于我从教程中加载了源代码,该教程的版本为1.8,对于任何最终出现此问题的人,这个问题在1.8.11中得到修复。 http://bugs.jqueryui.com/ticket/5490 – blacktie24 2011-04-03 04:39:05