我找到了一个将自动填充添加到表单的代码段:
问题是我无法弄清楚如何在select上提交表单。任何帮助将不胜感激:
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);
};
},
});
});
答案 0 :(得分:0)
试试这个
$("#search").autocomplete({
select: function (event, ui) {
var selectedObj = ui.item;
alert(selectedObj.value);
$("#search").val(selectedObj.value);
$('#formId').submit();
},
source: function(request, response) {
.................