我在多個輸入中使用typeahead.js方法typeahead
,我需要將選定值添加到當前輸入附近的隱藏輸入。
var $input = $('.typeahead');
$input.typeahead({
...
afterSelect: function (item) {
$(this).next('.input-hidden').val(item.id);
}
});
但$(this)
在這種情況下不起作用。
我創建了一個例子:https://jsfiddle.net/hvwy6a5n/
你可以查閱一下'this'指向。另外,如果可能,共享一個樣本作爲'JSFiddle'或'CodePen' – Rajesh
全局存儲$ input對象和用戶$ input.next()而不是$(this).next()怎麼樣? – Piotrek
警報($ input)未定義? –