JQuery自动完成功能无法加载

时间:2014-03-06 10:39:53

标签: javascript jquery jquery-autocomplete

在HTML输入字段上使用jQuery自动完成功能时,我在Firefox中遇到JavaScript错误。 “$('#geosearch').autocomplete is not a function” 使用Firebug我可以看到输入字段$('#geosearch')的jQuery属性设置为“1.11.0”,这意味着我使用的jQuery版本应该加载自动完成功能。

这是我正在使用的html代码:

<div class="panel">
    <label for="geosearch">Geographic search: </label>
    <input id="geosearch">
</div>

以下是我正在使用的javascript代码:

$('#geosearch').autocomplete({
            source: [ "a", "b", "c"],
            minLength: 2,
            select: function( event, ui ) {
                alert(ui.item ?"Selected: "+ui.item.value+"aka "+ui.item.id :"Nothing    selected, input was " + this.value);
            }
});

1 个答案:

答案 0 :(得分:1)

我为你创建了jsfiddle

<强> JS FIDDLE DEMO

<强> Jquery的:

  $(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
    });
  });

<强> HTML

  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">

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