我正在尝试遵循 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/