2014-01-09 76 views
2

我正在與jquery atocomplete並希望搜索點擊像谷歌youtube建議。但它不起作用。這裏是HTML代碼如何使點擊jquery自動完成搜索

<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)); 
} 

對此有何建議?

回答

4

單擊處理程序調用自動完成的search-method - 你需要設置minLength-option0,使工作

$("#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

+0

這爲我節省了很多時間,謝謝! –

+0

這仍然會查詢何時鍵入字符。我怎麼才能得到它只查詢時點擊一個特定的選擇器? – BenRacicot

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 
    } 
})