javascript 错误“未捕获的类型错误:$(...).datetimepicker 不是函数”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31962361/
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
Error "Uncaught TypeError: $(...).datetimepicker is not a function"
提问by Maria
I am trying to display two datetimepickers but i'm getting the error "Uncaught TypeError: $(...).datetimepicker is not a function" . I've installed :
我试图显示两个 datetimepicker,但我收到错误 "Uncaught TypeError: $(...).datetimepicker is not a function" 。我已经安装:
Install-Package Bootstrap.v3.Datetimepicker
安装包 Bootstrap.v3.Datetimepicker
Install-Package Bootstrap.v3.Datetimepicker.CSS
安装包 Bootstrap.v3.Datetimepicker.CSS
Here is the code :
这是代码:
@model MVCGreenhouseMonitoring.Models.Plotting.PlottingCalendarDropDownList
<head>
<title></title>
<script src="~/Scripts/jquery-1.9.1.js"></script>
<script src="~/Scripts/jquery-ui-1.11.4.min.js"></script>
<script src="~/scripts/moment-with-locales.min.js"></script>
<script src="~/scripts/bootstrap.min.js"></script>
<script src="~/scripts/bootstrap-datetimepicker.js"></script>
<link rel="stylesheet" href="~/Content/bootstrap-datetimepicker.css" />
</head>
<script>
$(function () {
$("#txtdatepicker1").datetimepicker();
$("#txtdatepicker2").datetimepicker();
});
</script>
@using (Html.BeginForm("IntervalReports", "Greenhouse", FormMethod.Post))
{
<table>
<tr>
<td>
<p>
Start Date: @Html.TextBoxFor(m => m.StartDateCalendar, new { @id = "txtdatepicker1", @style = "width:200px;" })
</p>
</td>
<td>
<p>
End Date: @Html.TextBoxFor(m => m.EndDateCalendar, new { @id = "txtdatepicker2", @style = "width:200px;" })
</p>
</td>
</tr>
</table>
<input type="submit" name="btnSubmit" value="Submit" />
}
I have all the necessary scripts in the Scripts folder.
我在 Scripts 文件夹中有所有必需的脚本。
回答by AndrewL64
Just include this on top of the other js files:
只需将其包含在其他 js 文件之上:
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
And wrap your script like this:
并像这样包装你的脚本:
jQuery(document).ready(function($){
jQuery("#txtdatepicker1").datetimepicker();
jQuery("#txtdatepicker2").datetimepicker();
});
回答by Grald
Make sure you included the right path of jquery script and must be the first in the head tag of the html you can get the latest jquery script here https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js
确保您包含了 jquery 脚本的正确路径,并且必须是 html 的 head 标记中的第一个您可以在此处获取最新的 jquery 脚本https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/ jquery.min.js
回答by RRK
You need to include the jQuery library before you can use jQuery UI n your page.
您需要先包含 jQuery 库,然后才能在您的页面中使用 jQuery UI。
Like this
像这样
<link rel="stylesheet" href="jquery-ui.min.css">
<script src="external/jquery/jquery.js"></script>
<script src="jquery-ui.min.js"></script>
回答by Curt
jQuery UI is dependant on the jQuery library.
jQuery UI 依赖于 jQuery 库。
jQuery UI is a widget and interaction library built on top of the jQuery JavaScript Library that you can use to build highly interactive web applications.
jQuery UI 是一个构建在 jQuery JavaScript 库之上的小部件和交互库,您可以使用它来构建高度交互的 Web 应用程序。
https://learn.jquery.com/jquery-ui/getting-started/
https://learn.jquery.com/jquery-ui/getting-started/
Make sure you include a reference to it before jQuery UI:
确保在 jQuery UI 之前包含对它的引用:
<head>
<title></title>
-- jQuery.js reference here --
<script type="text/javascript" src="~/Scripts/jquery-ui-1.11.4.min.js"></script>
<script type="text/javascript" src="~/scripts/moment-with-locales.min.js"></script>