0
$("input[type=text]").autocomplete({
minLength: 3,
source: function (request, response) {
        alert( $(this).val() );

我有 3 个不同的输入文本框,但$(this).attr("id")this.id两者都返回 undefined

4

2 回答 2

1

不确定里面有什么source关于this. 您始终可以将其记录到控制台以查看返回的内容。以下模式有助于在许多元素上实现插件

$("input[type=text]").each(function() {
    var id = this.id;
    $(this).autocomplete({
        minLength: 3,
        source: function(request, response) {
            alert(id);
        }
    });
});
于 2012-10-16T13:06:11.167 回答
0
alert( $(this.element).attr("id") );

作品。

于 2012-10-16T13:10:50.073 回答