【发布时间】:2016-02-13 20:57:07
【问题描述】:
我在多个输入中使用 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的形式分享样本 -
全局存储 $input 对象,用户 $input.next() 而不是 $(this).next() 怎么样?
-
alert($input) 未定义?
-
或者您很可能只使用
$input.next()而不进行其他更改 -
@Rajesh Guys,请参阅 JSFiddle 示例。
标签: javascript jquery typeahead.js