问题描述
我有一个DateTime Picker,我想限制用户输入中的错误,所以我将为将来的日期和时间使用任何输入。我想禁用比当前日期当前时间晚的时间。同时,如果用户要添加旧日期,则所有时间都将处于活动状态,并且可以从中选择任何时间。
<div class="form-group">
@Html.LabelFor(model => model.Start_Time,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Start_Time,new { htmlAttributes = new { @class = "form-control",ID = "StartTime" } })
@Html.ValidationMessageFor(model => model.Start_Time,"",new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.End_Time,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.End_Time,new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.End_Time,new { @class = "text-danger" })
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('input[type=datetime]').datetimepicker({
dateFormat: "dd/M/yy",changeMonth: true,changeYear: true,yearRange: "-60:+0",maxDate:0
});
});
</script>
我尝试编写此函数,但datetimepicker停止弹出,因此无法正常工作
$(document).ready(function () {
var theDay = new Date;
var theStartDate = $('#StartTime').value();
if (theStartDate === new Date) {
$('input[type=datetime]').datetimepicker({
dateFormat: "dd/M/yy",maxDate: 0,maxTime: 0
});
}
else if (theStartDate < new Date) {
$('input[type=datetime]').datetimepicker({
dateFormat: "dd/M/yy",maxDate: theDay
});
}
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)