jQuery自动完成 - 没有终止在空白处?

时间:2011-12-13 11:25:53

标签: javascript jquery jquery-ui autocomplete whitespace

使jQuery UI自动完成处理多个单词的最简单方法是什么?截至目前,空格将终止自动完成。

$.ajax({

                type: "GET",
                cache: false,
                dataType: 'json',
                url: "http://localhost/some_json",
                success:
                    function(response) {
                        $("#title").autocomplete({
                            source: response,
                            minLength: 2,
                            select: function (event, ui) {


                            }

                        }).data( "autocomplete" )._renderItem = function( ul, item ) {
                            //
                        }

                    }
});

2 个答案:

答案 0 :(得分:1)

我设置了这个基本的例子:

<label for="tags">Tags: </label>     <input id="tags">

var availableTags = ["Action alpha", "Action omega", "AppleScript", "Asp", "BASIC", "C", "C++", "Clojure", "COBOL", "ColdFusion", "Erlang", "Fortran", "Groovy", "Haskell", "Java", "JavaScript", "Lisp", "Perl", "PHP", "Python", "Ruby", "Scala", "Scheme"];
$("#tags").autocomplete({
    source: availableTags
});

对我来说,空间完成后自动完成。尝试挖掘Action a,您将在输入

下找到正确的建议

答案 1 :(得分:-1)

$("#tagnames").autocomplete("/tags/filter",
{
    max: 6, 
    highlightItem: true, 
    multiple: true, 
    multipleSeparator: " ",  
})

要为多个字词启用自动填充,您应设置选项multipletruemultipleSeparator" "