1

我找到了一个将自动完成添加到表单的片段:

http://jsfiddle.net/XxTuA/2/

问题是我不知道如何在选择时提交表单。任何帮助将不胜感激:

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

1 回答 1

0

试试这个

   $("#search").autocomplete({
     select: function (event, ui) {
         var selectedObj = ui.item;              
          alert(selectedObj.value);
          $("#search").val(selectedObj.value);
         $('#formId').submit();
        },
        source: function(request, response) {


.................
于 2013-03-19T06:23:49.303 回答