jQuery 未捕获的类型错误:$(...).autocomplete 不是函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32116618/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:51:06  来源:igfitidea点击:

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

jqueryjquery-uiautocomplete

提问by Andrew Kilburn

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.

我正在尝试实现一个 JQuery 自动完成文本框。我无法让我的自定义一个工作,所以我试图实现股票文本框而不是开始,这样我就可以修复这个错误。我不确定这是从哪里来的,因为我已经包含了页面(https://jqueryui.com/autocomplete/#default)建议的所有文件。除了演示 css 文件,但这并不重要,因为 css 不应干扰文本框的功能。

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>

回答by Rakesh Sadhula

You need to include jquery librarybefore jquery ui

你需要在jquery library之前包括jquery ui

check this fiddle

检查这个小提琴

回答by Serhat Akay

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>