Nic*_*ick 5 jquery-autocomplete typeahead twitter-bootstrap-3
我试试这个:
$('input[name=recerv_country]').typeahead({
remote : {
url: '?country=%QUERY',
filter: function(data) {
var resultList = data.map(function (item) {
return item.name;
});
return resultList;
}
},
updater : function (item) {
//item = selected item
//do your stuff.
alert(item.name);
alert('foo');
alert('bar');
//dont forget to return the item to reflect them into input
return item;
}
});
Run Code Online (Sandbox Code Playgroud)
什么都没发生,警报没有出现.我做错了什么?
$('input[name=recerv_country]').on('typeahead:selected', function(evt, item) {
alert(item.value);
});
Run Code Online (Sandbox Code Playgroud)
在 Twitter Bootstrap 3 中,Typeahead 插件已被删除。Bootstrap 建议使用https://github.com/twitter/typeahead.js代替。您似乎使用 typeahead.js 因为您使用远程调用。Typeahead.js 没有更新程序功能。
检查https://github.com/twitter/typeahead.js的自定义事件部分。typeahead:selected也许会满足您的需求。
另请参阅:Bootstrap 3 typeahead.js,使用 Bootstrap 2 中的类似功能