我有一个页面,我需要多个自动完成插件。我想使用类选择器来初始化自动完成代码。我的问题是在该代码中我必须能够选择触发元素的ID。有没有办法做到这一点?
//class selected input
$(".autocomplete-class").autocomplete({
autoSelect: true,
autoFocus: true,
delay: 200,
source: function (request, response) {
$.ajax({
url: "/Country/Find", type: "GET", dataType: "json",
data: { search: request.term, maxResults: 10 },
success: function (data) {
if (data.length == 0) {
var test = $(this);
$(/* ID of the input */).val(function (index, value) {
return value.substr(0, value.length - 1);
})
$(/* ID of the input */).autocomplete("search");
}
response($.map(data, function (item) {
return { label: item, value: item }
}))
}
})
}
});