我为我的网站实施了自动搜索模块,工作正常 现在的问题是,当用户输入它开始建议结果时,现在我想让这些结果可以点击 我的代码是
<input type="text" class="form-control input-lg" style="font-size:20px;padding-left:5px" name="query" id="search" required />
Jquery
$( function() {
$.widget("custom.catcomplete", $.ui.autocomplete, {
_renderMenu: function(ul, items) {
var that = this,
currentCategory = "";
$.each(items, function(index, item) {
if (item.category != currentCategory) {
ul.append("<li class='ui-autocomplete-category'>" + item.category + "</li>");
currentCategory = item.category;
}
that._renderItemData(ul, item);
});
}
});
$( "#search" ).catcomplete({
source : function(request,response){
var term = $("#search").val();
$.ajax({
type : "GET",
url : "ajax/auto_search.php",
dataType : "json",
data : {term : term},
success : function(data)
{
console.log(data);
response($.map(data.list, function(item) {
return {
value: item.content_title,
label: item.content_title,
category: item.category_name
};
}));
}
});
}
});
});
注意:当用户将鼠标悬停在建议的结果上时,它会在控制台jqueryui.min.js中抛出此内容:7未捕获的TypeError:无法读取未定义的属性“value”