javascript 未捕获的类型错误:未定义不是日期选择器中的函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26712372/
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
Uncaught TypeError: undefined is not a function in datepicker
提问by Shital Kadam
I am trying to use date picker of jquery in mvc4.
我正在尝试在 mvc4 中使用 jquery 的日期选择器。
It was giving me error:
它给了我错误:
Uncaught TypeError: undefined is not a function
My jQuery function is like:
我的 jQuery 函数是这样的:
$(document).ready(function () {
$('#dpFrom').datepicker();
});
html part is like:
html 部分是这样的:
<input type="text" id="dpFrom" />
I refered :
我提到:
Uncaught TypeError: undefined is not a function while using jQuery UI
未捕获的类型错误:使用 jQuery UI 时未定义不是函数
And included :
并包括:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
So total javascript became:
所以总的 javascript 变成了:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery('#dpFrom').datepicker();
});
</script>
Still its giving me error.
仍然给我错误。
Please help...
请帮忙...
回答by Chris
I think that you have a duplicate jQuery reference. Could you open a "View Source" on your web browser and enumerate your jQuery references? It is a common error and easily missed. Maybe a bundle definition or your layout and content pages have the same reference.
我认为您有重复的 jQuery 参考。您能否在 Web 浏览器上打开“查看源代码”并枚举您的 jQuery 引用?这是一个常见的错误,很容易被遗漏。也许捆绑定义或您的布局和内容页面具有相同的参考。
回答by Mohit
The path should be https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.jsnot //ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js in both referencing script and css tags
路径应该是https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js而不是 //ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery。引用脚本和 css 标签中的 min.js
回答by lothux1987
<script type="text/javascript">
$( "#datepicker" ).datepicker();
</script>
I tried this one, when i erase the function().
当我擦除函数()时,我尝试了这个。