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

匿名 (未验证) 提交于 2019-12-03 09:14:57

问题:

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.

<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

回答1:

The issue is because you're including two versions of jQuery. The first one has jQueryUI methods added to it. The second one then overwrites the first. Remove the last 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" /> 


回答2:

seems like you have added jQuery library twice.

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>



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!