我的页面上有两个datetimepicker。命名为' SartDate'并且' EndDate'。在StartDate上选择日期,将此日期设置为' EndDate的最小日期。。第一次正确工作。但是“开始日期”的日期是'重置,' EndDate的minDate'不 重新initiliaz
var date = null;
$("#jobPublishDate").bind("keyup blur change mouseup", function () {
$('#jobPublishDate').datetimepicker({ format: 'DD/MM/YYYY H:mm', showTodayButton: true, showClear: true, showClose: true });
var from = $("#jobPublishDate").val().split("/");
var newdate = from[1] + "/" + (from[0]) + "/" +from[2];
var f = new Date(newdate);
date = f;
});
$("#jobCloseDate").focusin(function () {
$('#jobCloseDate').datetimepicker({ format: 'DD/MM/YYYY H:mm', showTodayButton: true, showClear: true, showClose: true, minDate: date });
});
});
<label>StartDate></label>
<input ng-model="job.StrPublishDate" id="jobPublishDate">
<br/>
<label>EndDate></label>
<input ng-model="job.StrCloseDate" id="jobCloseDate">
答案 0 :(得分:0)
您需要挂钩dp.change
事件(在选择日期时触发),使用minDate
方法设置第二个选择器的最小日期。
var date = null;
$("#jobPublishDate").bind("keyup blur change mouseup", function () {
$('#jobPublishDate').datetimepicker({ format: 'DD/MM/YYYY H:mm', showTodayButton: true, showClear: true, showClose: true })
var from = $("#jobPublishDate").val().split("/");
var newdate = from[1] + "/" + (from[0]) + "/" +from[2];
var f = new Date(newdate);
date = f;
});
// Adds the date change event to the first picker
$("#jobPublishDate").on('db.change', function (e) {
// Get the DateTimePicker instance
var dp = $('#jobCloseDate').data('DateTimePicker');
// If the second picker has been initialized
if(typeof dp !== 'undefined') {
// Set the minimum date on the second picker
dp.minDate(e.date);
} else {
// If the close date picker is not initialized, stores the date for later use
date = e.date;
}
});
$("#jobCloseDate").focusin(function () {
$('#jobCloseDate').datetimepicker({ format: 'DD/MM/YYYY H:mm', showTodayButton: true, showClear: true, showClose: true, minDate: date });
});
您可以找到有关DateTimePicker方法here的更多信息。
答案 1 :(得分:0)
var date = null;
$("#jobPublishDate").bind("keyup blur change mouseup", function () {
var from = $("#jobPublishDate").val().split("/");
var newdate = from[1] + "/" + (from[0]) + "/" + from[2];
var f = new Date(newdate);
date = f;
$("#jobPublishDate").on('dp.change', function (e) {
var dp = $('#jobCloseDate').data('DateTimePicker');
if (typeof dp !== 'undefined') {
dp.minDate(e.date);
}
else {
date = e.date;
}
});
$("#jobCloseDate").focusin(function () {
$('#jobCloseDate').datetimepicker({ format: 'DD/MM/YYYY H:mm', showTodayButton: true, showClear: true, showClose: true, minDate: date });
});
本规范并解决问题。