jQuery datepicker() 未捕获的类型错误:未定义不是函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28248363/
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
jQuery datepicker() Uncaught TypeError: undefined is not a function
提问by John Britto
Can anyone please help me I am struggling with this problem for the past few day. Actually I included all the necessary plugins' but still the
任何人都可以帮助我,过去几天我一直在努力解决这个问题。实际上我包含了所有必要的插件,但仍然是
$('#datepicker').datepicker()
function is not defined ERROR.
$('#datepicker').datepicker()
功能未定义错误。
I included the same plugins' in the other jsp of my projects there the datepicker works perfectly.
我在我的项目的其他 jsp 中包含了相同的插件,日期选择器工作得很好。
This is what I tried.
这是我尝试过的。
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
$( '#datepicker' ).datepicker();
It throws the exception on page load itself. Thanks.
它在页面加载本身时引发异常。谢谢。
回答by John Britto
Please double check the js files you include if you include the same js file twice are different version of same file twice, It will conflict. Have patient to go through to entire jsp or html file to check the js files.
请仔细检查您包含的 js 文件,如果您两次包含相同的 js 文件两次是同一文件的不同版本,则会发生冲突。有耐心通过整个jsp或html文件来检查js文件。
回答by Vijaya Pandey
I just had this issue and solved it using $.noConflict();
:
我刚刚遇到了这个问题并使用$.noConflict();
以下方法解决了它:
Instead of $( '#datepicker' ).datepicker();
, I used:
而不是$( '#datepicker' ).datepicker();
,我使用了:
$.noConflict();
jQuery(document).ready(function ($) {
$("#datepicker").datepicker();
});
回答by Kentonbmax
Spent lots of time on this. Found the issue to datepicker function not found and or not working in Chrome. Using VS2015... Just about everything is dependant on JQuery so it must be at the very top. Use the following references or latest:
花了很多时间在这上面。发现未找到 datepicker 功能或在 Chrome 中无法正常工作的问题。使用 VS2015...几乎所有东西都依赖于 JQuery,所以它必须处于最顶端。使用以下参考资料或最新资料:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.min.css" />
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
- Open _layout.cshtml
- Paste at the top of each Environment section. Check the body as well. (I was missing the body)
- 打开_layout.cshtml
- 粘贴在每个环境部分的顶部。还要检查身体。(我错过了尸体)
回答by ssaltman
If you are using Wordpress, make sure you replace "$" with "jQuery" in the .js files.
如果您使用的是 Wordpress,请确保将 .js 文件中的“$”替换为“jQuery”。
回答by user7832009
check the reference what you have added and the reference what you have in the scripts folder. example: if you have referred [jquery-ui.min.js] in your .cshtml but you have [jquery-ui.min-1.13.0.js] in your scripts folder then this error will occurs
检查您添加的参考和脚本文件夹中的参考。示例:如果您在 .cshtml 中引用了 [jquery-ui.min.js],但在脚本文件夹中有 [jquery-ui.min-1.13.0.js],则会发生此错误