我找到了一个将自动完成添加到表单的片段:
问题是我不知道如何在选择时提交表单。任何帮助将不胜感激:
var suggestCallBack; // global var for autocomplete jsonp
$(document).ready(function () {
$("#search").autocomplete({
source: function(request, response) {
$.getJSON("http://suggestqueries.google.com/complete/search?callback=?",
{
"hl":"en", // Language
"jsonp":"suggestCallBack", // jsonp callback function name
"q":request.term, // query term
"client":"youtube" // force youtube style response, i.e. jsonp
}
);
suggestCallBack = function (data) {
var suggestions = [];
$.each(data[1], function(key, val) {
suggestions.push({"value":val[0]});
});
suggestions.length = 5; // prune suggestions list to only 5 items
response(suggestions);
};
},
});
});