[英]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.