如果我单击仅搜索“ 2018”的搜索按钮,但是如果我按搜索“ 2018歌曲”的PC上的Enter按钮,我想搜索“ 2018”,如果我按PC上的Enter按钮,我该如何使用Autocomplete | jQuery UI
对其进行修复 var suggestCallBack;
document.addEventListener('DOMContentLoaded', function() {
$("#searchbox").autocomplete({
source: function(request, response) {
$.getJSON("http://suggestqueries.google.com/complete/search?callback=?",
{
"hl":"en",
"ds":"yt",
"jsonp":"suggestCallBack",
"q":request.term,
"client":"youtube"
}
);
suggestCallBack = function (data) {
var suggestions = [];
$.each(data[1], function(key, val) {
suggestions.push({"value":val[0]});
});
suggestions.length = 10;
response(suggestions);
};
},
autoFocus: true,
select: function(event, ui) {
$(event.target).val(ui.item.value);
$('#searchform').submit();
return false;
}
});
});
在这种情况下,我想搜索(2018)而不是(2018歌曲),所以如果我单击搜索按钮之前可以怎么说,我会搜索(2018),但如果按Enter按钮,则搜索(2018歌曲)我可以解决这个问题吗?
答案 0 :(得分:1)