我在多个输入中使用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)未定义? –