根据第一个选择第二个日期选择器的minDate [英] change the second datepicker's minDate depending the first one
问题描述
我在同一页面中有两个datePicker,我想根据第一个更改第二个datepicker的minDate.这是我的代码:
I have two datePickers in the same page and I wanna change the second datepicker's minDate depending the first one. Here is my code:
$("#datepickerDepart" ).datepicker({
dateFormat: "mm-dd-yy",
minDate: 0,
onSelect: function(dateText, inst) {
var m = dateText.substring(0,2);
var d = dateText.substring(3,5);
var y = dateText.substring(6,10);
console.log(d);
console.log(m);
console.log(y);
var newDate = new Date(y,m-1,d);
console.log(newDate);
$('#datepickerReturn').val("");
$('#datepickerReturn').datepicker({
dateFormat: "mm-dd-yy",
minDate: newDate
})
}
});
但是我有一个问题,第一次在第一个datePicker中选择一个日期时,第二个的minDate将根据此设置,但是当我重新选择第一个时,第二个datePicker的minDate将不再更改,它将保持不变.我不知道为什么请帮忙!
But I have a question, the first time I select a date in the first datePicker, the minDate of second one will be set according to this, but when I reselect the first one, the second datePicker's minDate won't change anymore, it will remain. I don't know why. Please help!!
我只想更改第二个日期的minDate,只要选择的第一个日期更改即可.
I just wanna the minDate of the second one will change as long as the selected date of the first one change.
推荐答案
$("#strStartDate").datepicker({
dateFormat: 'dd/mm/yy',
constrainInput: true,
firstDay: 1,
hideIfNoPrevNext: true,
onSelect: function(){
if ($("#strStartDate").val() > $("#strEndDate").val()){
$("#strEndDate").val($("#strStartDate").val());
}
}
});
$("#strEndDate").datepicker({
dateFormat: 'dd/mm/yy',
constrainInput: true,
firstDay: 1,
hideIfNoPrevNext: true,
beforeShow: function (input, inst) {
inst.settings.minDate = $("#strStartDate").val();
}
});
这篇关于根据第一个选择第二个日期选择器的minDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!