简体   繁体   English

jQuery自动完成 - 未捕获TypeError:undefined不是函数

[英]jQuery autocomplete - Uncaught TypeError: undefined is not a function

I'm trying to add the jquery autocomplete on my search-textbox, but for some reason I can't get it to work. 我正在尝试在我的搜索文本框中添加jquery自动完成功能,但由于某种原因我无法使其工作。 It looks like I have all neccesary jquery loaded and no differences in versions. 看起来我已经加载了所有必要的jquery,版本没有差异。 I've tried every (atleast the one I've found) suggested solution, but none of them have worked. 我已经尝试了每一个(至少我发现的那个)建议的解决方案,但它们都没有奏效。

my html: 我的HTML:

 <input type="search" name="searchTerm" 
data-test-autocomplete="@Url.Action("AutoComplete")" />

my js: 我的js:

$(function() {
  var createAutoComplete = function() {
    var $input = $(this);

    var options = {
      source: $input.attr("data-test-autocomplete")
    };

    $input.autocomplete(options);
  };


  $("input[data-test-autocomplete]").each(createAutoComplete);

});

bundle being called inside the _Layout.cshtml at the end of the body: 在身体末尾的_Layout.cshtml内调用bundle:

  bundles.Add(new ScriptBundle("~/bundles/test").Include(
              "~/Scripts/jquery-{version}.js",
              "~/Scripts/jquery-ui-{version}.js",
              "~/Scripts/jquery.unobtrusive*",
              "~/Scripts/jquery.validate*",
              "~/Scripts/test.js"));

Scripts being loaded: 正在加载的脚本:

<script src="/Scripts/jquery-1.10.2.js"></script>
<script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>
<script src="/Scripts/test.js"></script>
<script src="/Scripts/bootstrap.js"></script>
<script src="/Scripts/respond.js"></script>

Thanks in advance. 提前致谢。

What is undefined is clearly .autocomplete jQuery function. 什么是undefined显然是.autocomplete jQuery函数。 Please, see that in the "Scripts being loaded" part of your question jQuery UI is completely missing. 请注意,在你的问题的“正在加载的脚本”部分中,jQuery UI完全缺失。

You're correctly including it in your bundle, as "~/Scripts/jquery-ui-{version}.js" so the only possible explanation for the failure is that the jQuery UI script file is missing from that route (or that you're rendering the worng bundle in your layout or view Razor code). 您正确地将它包含在您的包中,如"~/Scripts/jquery-ui-{version}.js"所以唯一可能的解释是该路由中缺少jQuery UI脚本文件(或者您'在你的布局中渲染worng包或查看Razor代码)。

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

相关问题 Uncaught TypeError:未定义不是函数jQuery自动完成 - Uncaught TypeError: undefined is not a function jquery autocomplete jQuery Uncaught TypeError:$(…).autocomplete不是函数 - jQuery Uncaught TypeError: $(…).autocomplete is not a function jQuery的,遗漏的类型错误:未定义是不是一个函数 - Jquery, Uncaught TypeError: undefined is not a function 未捕获的TypeError:undefined不是jQuery的函数 - Uncaught TypeError: undefined is not a function with jQuery 未捕获的TypeError:undefined不是函数-不是JQuery - Uncaught TypeError: undefined is not a function - not JQuery 未捕获的TypeError:undefined不是函数jquery - Uncaught TypeError: undefined is not a function jquery 未捕获的TypeError:undefined不是函数(jQuery和jQuery Easing) - Uncaught TypeError: undefined is not a function (jQuery & jQuery Easing) 未捕获的TypeError:$(…).autocomplete不是函数 - Uncaught TypeError: $(…).autocomplete is not a function JQuery 自动完成:未捕获的类型错误:无法读取未定义的属性“值” - JQuery autocomplete: Uncaught TypeError: Cannot read property 'value' of undefined 未捕获的TypeError:无法读取未定义的JQUERY自动完成的属性&#39;length&#39; - Uncaught TypeError: Cannot read property 'length' of undefined JQUERY autocomplete
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM