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

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

I'm trying to implement a JQuery autocomplete text box. I couldn't get my custom one to work, so I'm trying to implement the stock text box instead to begin with so I can fix this error. I'm not sure where this is coming from considering that I have included all of the files which the page(https://jqueryui.com/autocomplete/#default) has suggested. Except the demo css file, but this doesn't matter as the css shouldn't intefere with the functionality of the text box.

Here is the code:

<head>     <title></title>     <link href="~/Content/ClientDash.css" rel="stylesheet" />     <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">     <script>         $(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             });         });     </script> </head>  <div class="ui-widget">             <label for="tags">Tags: </label>             <input id="tags">         </div> 

Layout:

<head> <script src="~/Scripts/jquery-2.1.4.min.js"></script>     <script src="~/Scripts/jquery-ui-1.11.4.min.js"></script> </head> 

回答1:

You need to include jquery library before jquery ui

check this fiddle



回答2:

Change the beginning of your code with the one below. You are missing some files.

<title></title>     <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">       <script>         $(function () { 

<html lang="en"> <head>   <meta charset="utf-8">   <title>jQuery UI Autocomplete - Default functionality</title>   <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">   <script>   $(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     });   });   </script> </head> <body>   <div class="ui-widget">   <label for="tags">Tags: </label>   <input id="tags"> </div>     </body> </html>


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