1

我对用于自动完成搜索的 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>
4

1 回答 1

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
    });
});
于 2013-08-11T20:04:30.767 回答