[英]BootStrap : Uncaught TypeError: $(…).datetimepicker is not a function
[英]Error “Uncaught TypeError: $(…).datetimepicker is not a function”
我试图显示两个datetimepickers,但我收到错误“Uncaught TypeError:$(...)。datetimepicker不是一个函数”。 我安装了:
Install-Package Bootstrap.v3.Datetimepicker
Install-Package Bootstrap.v3.Datetimepicker.CSS
这是代码:
@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" />
}
我在Scripts文件夹中有所有必需的脚本。
只需将其包含在其他js文件之上:
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
并像这样包装你的脚本:
jQuery(document).ready(function($){
jQuery("#txtdatepicker1").datetimepicker();
jQuery("#txtdatepicker2").datetimepicker();
});
确保你包含正确的jquery脚本路径,并且必须是html的head标签中的第一个,你可以在这里获得最新的jquery脚本https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/ jquery.min.js
您需要先包含jQuery库,然后才能在页面中使用jQuery UI。
像这样
<link rel="stylesheet" href="jquery-ui.min.css">
<script src="external/jquery/jquery.js"></script>
<script src="jquery-ui.min.js"></script>
jQuery UI依赖于jQuery库。
jQuery UI是一个构建在jQuery JavaScript库之上的小部件和交互库,可用于构建高度交互的Web应用程序。
https://learn.jquery.com/jquery-ui/getting-started/
确保在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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.