我有两个Kendo DatePickers来选择开始日期和结束日期。加载页面时,它们都显示今天的日期。选择开始日期后,我编写了一个脚本,限制用户选择开始日期之后的日期。但是,希望DatePicker值中的结束日期更新为先前选择的开始日期。任何帮助都会很棒。
这是我的代码:
<div class="form-group">
@Html.LabelFor(m => m.StartDate, new { @class = "col-md-2 control-label" })
<div class="col-md-10 k-content">
@(Html.Kendo().DatePicker()
.Name("StartDate")
.Max(new DateTime(2020, 12, 31))
.Value(DateTime.Today.AddDays(1))
.Events(e => e.Change("startChange"))
.Culture(ViewBag.Culture)
.HtmlAttributes(new { @data_val = "false" })
)
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.EndDate, new { @class = "col-md-2 control-label" })
<div class="col-md-10 k-content">
@(Html.Kendo().DatePicker()
.Name("EndDate")
.Min(DateTime.Today)
.Max(new DateTime(2020, 12, 31))
.Value(DateTime.Today.AddDays(1))
.Events(e => e.Change("endChange"))
.Culture(ViewBag.Culture)
.HtmlAttributes(new { @data_val = "false" })
)
</div>
</div>
这是剧本:
function startChange() {
var endPicker = $("#EndDate").data("kendoDatePicker"),
startDate = this.value();
if (startDate) {
startDate = new Date(startDate);
startDate.setDate(startDate.getDate());
endPicker.min(startDate);
}
}
function endChange() {
var startPicker = $("#StartDate").data("kendoDatePicker"),
endDate = this.value();
if (endDate) {
endDate = new Date(endDate);
endDate.setDate(endDate.getDate());
}
}
答案 0 :(得分:0)
刚刚找到答案,那太傻了。
function startChange() {
var endPicker = $("#EndDate").data("kendoDatePicker"),
startDate = this.value();
if (startDate) {
startDate = new Date(startDate);
startDate.setDate(startDate.getDate());
endPicker.min(startDate);
endPicker.value(startDate);//added this line
}
}