【发布时间】:2017-06-26 23:17:08
【问题描述】:
我正在尝试从 Bootstrap 3 Typeahead (https://github.com/bassjobsen/Bootstrap-3-Typeahead) 回调方法中访问输入元素,但似乎 $(this)、this、$(this)[0] 以及描述的任何其他技术在这个问题上,Get input element from Bootstrap typeahead 不起作用,官方文档中对此一无所知。如果使用包含多个元素的选择器在一个页面上初始化多个 Typeahead 实例,这一点非常重要,但在每个回调中只应处理相关的单个元素。
$(".typeahead").typeahead({
afterSelect: function(item) {
// the only parameter, item, is the JSON of the
// currently selected item, chosen from the list.
// Neither $(this) nor this are references to the
// affected input element, so how do I access the
// input element from within this callback?
},
...
});
【问题讨论】:
标签: jquery twitter-bootstrap-3 typeahead.js bootstrap-typeahead twitter-typeahead