简体   繁体   English

jQuery Uncaught TypeError:$(…).autocomplete不是函数

[英]jQuery Uncaught TypeError: $(…).autocomplete is not a function

I have the following files 我有以下文件

<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<link href="css/style2.css" rel="stylesheet" type="text/css" />
<link href="css/default.css" rel="stylesheet" type="text/css" />
<link href="css/index.css" rel="stylesheet" type="text/css" />
<script src="js/jquery.js" type="text/javascript"></script>

That was working fine but when I added other JS files like DateTimepicker then my autocomplete function stops working. 那工作正常,但是当我添加其他JS文件(如DateTimepicker)时,我的自动完成功能停止工作。

<script src="js/jquery.datetimepicker.full.js" type="text/javascript"></script>
<link href="css/jquery.datetimepicker.css" rel="stylesheet" type="text/css" />

Error: 错误:

Uncaught TypeError: $(...).autocomplete is not a function 未捕获的TypeError:$(...)。autocomplete不是函数

The issue is because you're including two versions of jQuery. 问题是因为您包括两个版本的jQuery。 The first one has jQueryUI methods added to it. 第一个添加了jQueryUI方法。 The second one then overwrites the first. 然后,第二个覆盖第一个。 Remove the last jQuery script include. 删除最后一个jQuery script include。

<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<!-- REMOVE THIS >> <script src="js/jquery.js" type="text/javascript"></script> -->
<script src="js/jquery.datetimepicker.full.js"></script>

<link rel="stylesheet" type="text/css" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="/resources/demos/style.css">
<link rel="stylesheet" type="text/css" href="css/jquery.datetimepicker.css" />
<link rel="stylesheet" type="text/css" href="css/style2.css" />
<link rel="stylesheet" type="text/css" href="css/default.css" />
<link rel="stylesheet" type="text/css" href="css/index.css" />

seems like you have added jQuery library twice. 好像您已经两次添加了jQuery library

keep it only once. 只保留一次。

Either this one <script src="//code.jquery.com/jquery-1.10.2.js"></script> or <script src="js/jquery.js" type="text/javascript"></script> <script src="//code.jquery.com/jquery-1.10.2.js"></script><script src="js/jquery.js" type="text/javascript"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM