我对所有输入字段使用自动填充功能,例如
$('input').autocomplete({
minLength: 1,
source: "{site_url}publish/my_autocomplete"
});
它工作正常,但是当我想发送所选的输入ID时,如
$('input').autocomplete({
minLength: 1,
source: "{site_url}publish/my_autocomplete?key="+$(this).attr('id')
});
它不起作用且键未定义,任何人都可以建议我
答案 0 :(得分:1)
在您的代码this
中,并不代表您假设的当前input
。
试试这个
$('input').each(function(){
var $this = $(this);
$this.autocomplete({
minLength: 1,
source: "{site_url}publish/my_autocomplete?key=" + $this.attr('id')
});
})