javascript - TypeError : $(. ..).easyAutocomplete 不是一个函数

标签 javascript jquery autocomplete easyautocomplete

我正在尝试遵循 jquery easyAutocomplete docs并收到此错误。我知道这是一个非常常见的问题,并且已经有很多人问过这个问题。但他们似乎都没有消除我的错误。这是我的代码

测试.js

var options = {
  url: "places.json",
  getValue: "name",

  list: {
    match: {
      enabled: true
    }
  },

  theme: "square"
};

$("#textbox").easyAutocomplete(options);

html

<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>test</title>

    <link
      rel="stylesheet"
      href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css"
    />
  </head>
  <body>
    <div>
      Location: <br />
      <br />
      <input type="text" name="enterlocation" id="textbox" />
      <button>enter</button>
    </div>
  </body>

  <script src="https://code.jquery.com/jquery-3.4.1.js"></script>
  <script async src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <script src="test.js"></script>
</html>

json:

[
  { "name": "Afghanistan", "code": "AF" },
  { "name": "Aland Islands", "code": "AX" },
  { "name": "Albania", "code": "AL" },
  { "name": "Algeria", "code": "DZ" },
  { "name": "American Samoa", "code": "AS" }
]

最佳答案

EasyAutocomplete guide ,它说:

In order to use EasyAutocomplete, add these files in header section of your page.

<!-- JS file -->
<script src="path/to/jquery.easy-autocomplete.min.js"></script> 

<!-- CSS file -->
<link rel="stylesheet" href="path/to/easy-autocomplete.min.css"> 

<!-- Additional CSS Themes file - not required-->
<link rel="stylesheet" href="path/to/easy-autocomplete.themes.min.css"> 

Remember to include jQuery file. You can download library from the jQuery website. Best practice is to use CDN server:

<!-- Using jQuery with a CDN -->
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>

基于此,您需要在 jQuery 之后、您自己的代码之前包含 jquery.easy-autocomplete.min.js。您还应该包含 easy-autocomplete.min.css

关于javascript - TypeError : $(. ..).easyAutocomplete 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57310815/

相关文章:

javascript - 如何使用 javascript 轻松编码 HTTP 链接?

javascript - 在 Drupal 8 中附加或包含一个 js 文件

jquery - 状态成功时的 Ajax 用户通知

javascript - 发布后 JQuery 发布请求失败且没有警报

vim - 在 vim 中获取 ocamlmerlin 自动完成功能

jquery - 搜索框上的向上/向下箭头 jQuery 事件

javascript - ACE 编辑器自动完成 - 自定义字符串

javascript - 谷歌地图制作模糊效果

javascript - 使用 tsc 时从 p5.play.js 生成 d.ts 文件时出现问题

javascript - 等待 AngularJs Ajax 调用完成