回答

1

您可以只聽你的輸入改變事件是這樣的:

$('input.typeahead').on('change', function() { ... })

+0

輸入只在輸入失去焦點時觸發更改事件。 – Ziggy

+1

然而這似乎是唯一對我有用的東西,謝謝! – Tumtum

10

這樣做的一種新的方式是:

$('.input').typeahead({ 
    // snip 
}).on('typeahead:selected', function() { 
    // on selected 
}); 
+0

這很好,+1因爲這對我有用。你能否解釋爲什麼這個文件說明了它的前衛:選擇它的真正typeahead:選擇? https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md#custom-events – MiKE

+1

nope,這是正確的回到'13,也許api在dev版本中改變? – MarZab

2
$('#myselector').typeahead({ 
itemSelected:function(data,value,text){ 
    console.log(data) 
    alert('value is'+value); 
    alert('text is'+text); 
}, 
//your other stuffs 
}); 

你只是傳中itemSelected回調函數,它會給你選定的項目。

希望這會爲你工作。

相關問題