Jquery 无法使日期选择器工作
取决于我使用的主题-我的日期选择器将无法工作,它正在杀死我 我以前做过很多次,但我有一个奇怪的反应:我可以让它工作,没有我的自定义引导主题,但有了它,它将无法工作。页面按其外观加载,但日期选择器不起作用,但如果我删除主题,它会起作用 我之所以说这很奇怪,是因为我两天前在一个项目中使用了这个主题,它工作得非常好,但现在它在这个新项目中不起作用Jquery 无法使日期选择器工作,jquery,asp.net-mvc,datepicker,Jquery,Asp.net Mvc,Datepicker,取决于我使用的主题-我的日期选择器将无法工作,它正在杀死我 我以前做过很多次,但我有一个奇怪的反应:我可以让它工作,没有我的自定义引导主题,但有了它,它将无法工作。页面按其外观加载,但日期选择器不起作用,但如果我删除主题,它会起作用 我之所以说这很奇怪,是因为我两天前在一个项目中使用了这个主题,它工作得非常好,但现在它在这个新项目中不起作用 @model WADTrackerApplication.Models.Weight @{ ViewBag.Title = "Create"; }
@model WADTrackerApplication.Models.Weight
@{
ViewBag.Title = "Create";
}
<html>
<head>
</head>
<body>
<div class="container">
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Weight</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model._Weight, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model._Weight, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model._Weight, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DateTime, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DateTime, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DateTime, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.AdditonalComments, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.AdditonalComments, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.AdditonalComments, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
</div>
<link href="~/Content/bootstrap-theme.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/moment.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/bootstrap-datetimepicker.min.js"></script>
<link href="~/Content/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<script src="~/Scripts/bootstrap-datetimepicker.js"></script>
<script type="text/javascript">
$(function () {
$('DateTime').datetimepicker({
viewMode: 'years',
format: 'DD/MM/YYYY'
});
});
</script>
</body>
</html>
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
@model WADTrackerApplication.Models.Weight
@{
ViewBag.Title=“创建”;
}
@使用(Html.BeginForm())
{
@Html.AntiForgeryToken()
重量
@Html.ValidationSummary(true,“,new{@class=“text danger”})
@LabelFor(model=>model.\u-Weight,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.\u-Weight,new{htmlAttributes=new{@class=“form-control”}})
@Html.ValidationMessageFor(model=>model._-Weight,“,new{@class=“text-danger”})
@LabelFor(model=>model.DateTime,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.DateTime,new{htmlAttributes=new{@class=“form control”}})
@Html.ValidationMessageFor(model=>model.DateTime,“,new{@class=“text danger”})
@LabelFor(model=>model.AdditonalComments,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.AdditonalComments,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.AdditonalComments,“,new{@class=“text danger”})
}
$(函数(){
$('DateTime').datetimepicker({
查看模式:“年”,
格式:“DD/MM/YYYY”
});
});
@ActionLink(“返回列表”、“索引”)
@节脚本{
@Scripts.Render(“~/bundles/jqueryval”)
}
您的javascript代码有一个错误的选择器,$('DateTime')
将选择标记中不存在的DateTime类型的所有元素
将描述性类或ID添加到要充当日期选择器的输入:
@Html.EditorFor(model => model.DateTime, new { htmlAttributes = new { @class = "form-control date-picker" } })
然后在js代码段中使用该选择器:
$(function () {
$('.date-picker').datetimepicker({
viewMode: 'years',
format: 'DD/MM/YYYY'
});
});
$('DateTime').datetimepicker({?您需要指定它是一个类还是一个id,对吗?即使我键入“.datepicker()”,如果我选择“layout=null”,它甚至不会开始尝试自动完成它然后它可以工作,但是页面上没有css。如果完全删除javascript代码呢?Bootstrap和Jquery应该在脚本链接或整个“$(函数…”中自动完成其余的工作