如何从 Bootstrap 3 Typeahead 回调中获取对输入元素的引用?
How to get reference to input element from within Bootstrap 3 Typeahead callback?
我正在尝试从 Bootstrap 3 Typeahead (https://github.com/bassjobsen/Bootstrap-3-Typeahead) callback methods, but it seems that $(this), this, $(this)[0], and any other techniques described on this question, 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?
},
...
});
函数内
this.$element
查看源代码
https://github.com/bassjobsen/Bootstrap-3-Typeahead/blob/master/bootstrap3-typeahead.js
我正在尝试从 Bootstrap 3 Typeahead (https://github.com/bassjobsen/Bootstrap-3-Typeahead) callback methods, but it seems that $(this), this, $(this)[0], and any other techniques described on this question, 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?
},
...
});
函数内
this.$element
查看源代码 https://github.com/bassjobsen/Bootstrap-3-Typeahead/blob/master/bootstrap3-typeahead.js