我有两个输入文本框,第一个输入开始日期,第二个输入结束日期。当我尝试在“开始”输入框中选择日期时,它会选择 另一个输入框中的同一日期:
但是我想要这样的输出:
这里有两个输入
input type="text" class="form-control" placeholder="Start Date" name="Start" id="dt1"
input type="text" class="form-control" placeholder="End Date" name="End" id="dt2"
P.S。我从互联网上的某个地方获得了代码。
$(document).ready(function () {
$("#dt1").datepicker({
dateFormat: "dd-M-yy",
//minDate: 0,
onSelect: function () {
var dt2 = $('#dt2');
var startDate = $(this).datepicker('getDate');
//add 30 days to selected date
startDate.setDate(startDate.getDate() + 30);
var minDate = $(this).datepicker('getDate');
var dt2Date = dt2.datepicker('getDate');
//difference in days. 86400 seconds in day, 1000 ms in second
var dateDiff = (dt2Date - minDate)/(86400 * 1000);
//dt2 not set or dt1 date is greater than dt2 date
if (dt2Date == null || dateDiff < 0) {
dt2.datepicker('setDate', minDate);
}
//dt1 date is 30 days under dt2 date
else if (dateDiff > 30){
dt2.datepicker('setDate', startDate);
}
//sets dt2 maxDate to the last day of 30 days window
dt2.datepicker('option', 'maxDate', startDate);
//first day which can be selected in dt2 is selected date in dt1
dt2.datepicker('option', 'minDate', minDate);
}
});
$('#dt2').datepicker({
dateFormat: "dd-M-yy",
// minDate: 0
});
});