多个自动填充搜索输入字段

时间:2013-08-11 20:01:18

标签: jquery jquery-ui jquery-ui-autocomplete

我对自动完成搜索的jQuery插件有点问题,我无法在同一时间内设置两个带自动完成搜索的字段。有人能帮我吗? 这是我的html + jQuery代码:

<!doctype html>

<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet"
    href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<!-- <script src="js/fintp/fintpAutoCompleteSearch.js"></script> -->
<script>
    $(function() {
        var availableTags = [ "ActionScript", "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
        });
        $("#tags1").autocomplete({
            source : availableTags
        });
    });
</script>
</head>
<body>

    <div class="ui-widget">
        <label for="tags">Tags: </label> <input id="tags" /><br> <label
            for="tags1">Tags: </label> <input id="tags1" />
    </div>


</body>
</html>

1 个答案:

答案 0 :(得分:2)

基于此jsFiddle DEMO,它可以正常工作。

$(function () {
    var availableTags = ["ActionScript", "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
    });
    $("#tags1").autocomplete({
        source: availableTags
    });
});