0

我試圖從Bootstrap 3 Typeahead(https://github.com/bassjobsen/Bootstrap-3-Typeahead)回調方法中訪問輸入元素,但似乎$(this),this,$(this)[0]以及此問題中描述的任何其他技術,Get input element from Bootstrap typeahead,都不起作用,官方文件上沒有這方面的內容。如果使用包含多個元素的選擇器在一個頁面上初始化Typeahead的多個實例,那麼這非常重要,但每個回調中只應處理相關的單個元素。如何從Bootstrap 3 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? 
    }, 
    ... 
}); 

回答

相關問題