函数外如何获得jQuery Autocomplete的response数组。
[JavaScript] 纯文本查看 复制代码 //搜索文本框变量赋值
$("body").on("focus", ".inpSearch", function () {
var cache = {};
$(this).autocomplete({
source: function (request, response) {
var term = request.term;
if (term in cache) {
response(cache[term]);
return;
};
$.getJSON("/asset/php/laobao/getSearch.php", request, function (data, status, xhr) {
if (data.length > 0) {
cache[term] = data;
response(data);
} else {
response(['null']);
$(".ui-autocomplete").html('<span style="margin: 0 10px"><i class="fas fa-exclamation"></i> 无匹配结果</span>');
};
});
}
})
});
//==搜索文本框失去焦点=================
$("body").on("blur", ".inpSearch", function () {
console.log($(this).autocomplete( "option", "source" ));
console.log(这里输出数组);
// 这里,如何获得autocomplete的response数组
}); |