$("input[type=text]").autocomplete({
minLength: 3,
source: function (request, response) {
alert( $(this).val() );
我有 3 个不同的输入文本框,但$(this).attr("id")
或this.id
两者都返回 undefined
$("input[type=text]").autocomplete({
minLength: 3,
source: function (request, response) {
alert( $(this).val() );
我有 3 个不同的输入文本框,但$(this).attr("id")
或this.id
两者都返回 undefined
不确定里面有什么source
关于this
. 您始终可以将其记录到控制台以查看返回的内容。以下模式有助于在许多元素上实现插件
$("input[type=text]").each(function() {
var id = this.id;
$(this).autocomplete({
minLength: 3,
source: function(request, response) {
alert(id);
}
});
});
alert( $(this.element).attr("id") );
作品。