我正在使用jquery atocomplete,想要点击像google youtube这样的建议。但它不起作用。这是HTML代码
<ul class="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content ui-corner-all" id="ui-id-1" tabindex="0" style="display: none; top: 488px; left: 248px; width: 542px;">
<li class="ui-menu-item" role="presentation">
<a id="ui-id-6" class="ui-corner-all" tabindex="-1">Activity</a>
</li>
<li class="ui-menu-item" role="presentation">
<a id="ui-id-7" class="ui-corner-all" tabindex="-1">Apply online</a>
</li>
</ul>
和jquery在这里
$( "#site-search-query" ).autocomplete({
source: function(request, response) {
var results = $.ui.autocomplete.filter(res, request.term);
response(results.slice(0, 4));
}
对此有何建议?
答案 0 :(得分:4)
在点击处理程序中调用自动填充的search-method - 您需要将minLength-option设置为0
才能使其正常工作
$("#site-search-query").autocomplete({
source: function (request, response) {
var results = $.ui.autocomplete.filter(res, request.term);
response(results.slice(0, 4));
},
minLength: 0
}).click(function () {
$(this).autocomplete('search')
});
演示:Fiddle
答案 1 :(得分:0)
试试这个:
$( "#site-search-query" ).autocomplete({
source: function(request, response) {
var results = $.ui.autocomplete.filter(res, request.term);
response(results.slice(0, 4));
},
select: function( event, ui ) {
//Your search function
}
})