문제

I get a JavaScript error in Firefox when using the jQuery autocomplete function on a HTML input field. "$('#geosearch').autocomplete is not a function" Using Firebug I can see that the jQuery attribute of the input field $('#geosearch') is set to "1.11.0" which means that the version of jQuery I am using should load the autocomplete function.

Here is the html code I am using :

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

Here is the javascript code I am using :

$('#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);
            }
});
도움이 되었습니까?

해결책

I created jsfiddle for you check

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top