jQuery 日期选择器不是函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15426255/
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
datepicker is not a function
提问by NewUser
This question is already asked many times but none of them worked for me. I am trying to use this date picker in a JSP
file. This is my script
这个问题已经被问过很多次了,但没有一个对我有用。我正在尝试在JSP
文件中使用此日期选择器。这是我的脚本
<head>
<title>My Home</title>
<link rel="stylesheet" type="text/css"
href="../resource/css/page-style.css" />
<link rel="stylesheet" type="text/css"
href="../resource/css/jQuery-ui.css" />
<script src="../resource/js/jquery-1.9.1.js"></script>
<script src="../resource/js/jquery-ui.js"></script>
<script type="text/javascript" src="../resource/js/form-elements.js"></script>
<script type="text/javascript">
$("document").ready(function() {
$("#shortcuts").load("shortcut.html");
$("#datepicker").datepicker();
alert('jQuery is working');
});
</script>
</head>
The shortcut
file is loading perfectly, alert is also showing. I get error message as TypeError: $(...).datepicker is not a function
. I am not facing this problem if I run this script in a html file placed in my desktop, when I copy the come code to my IDE and run it I get this error in my console. Please suggest me what can I do? I know this question is asked several times I have checked every answer this is the only linkhaving close match to my prob but didn't work for me.
该shortcut
文件加载完美,警报也呈现出。我收到错误消息为TypeError: $(...).datepicker is not a function
. 如果我在桌面上的 html 文件中运行此脚本,则不会遇到此问题,当我将代码复制到我的 IDE 并运行它时,我在控制台中收到此错误。请建议我该怎么办?我知道这个问题被问了好几次我已经检查了每个答案,这是与我的概率非常接近但对我不起作用的唯一链接。
回答by PSR
The problem is with your imported files.I think you have not placed them properly.
问题在于您导入的文件。我认为您没有正确放置它们。
Try to import these files
尝试导入这些文件
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
It is working for me.
它对我有用。
see here for more information
请参阅此处了解更多信息
回答by Mark Kadlec
Double check that there are no JQuery references afteryour JQuery-ui reference.
仔细检查您的 JQuery-ui 引用后是否没有 JQuery引用。
I had an extra JQuery reference that came after my JQuery-ui reference and lost an hour chasing the problem. That will cause the datepicker not found error.
我有一个额外的 JQuery 参考,它是在我的 JQuery-ui 参考之后出现的,但为了解决这个问题浪费了一个小时。这将导致未找到日期选择器错误。
回答by Dulith De Costa
This is something to do with the import files. I also faced the same scenario and following imports helped me to overcome the following issue "datepicker is not a function".
这与导入文件有关。我也遇到了同样的情况,以下导入帮助我克服了以下问题“日期选择器不是功能”。
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">