问题
I'm trying to build 2 datepickers with the following restriction:
- startDate >= tomorrow
- endDate > startDate
- endDate can't select a date if startDate not selected
just like the checkin / checkout hotel rooms. I'm using this so far
function customRange(input)
{
return {
minDate: (input.id == "startDate" ? new Date(2008, 12 - 1, 1) : null),
minDate: (input.id == "endDate" ? $("#startDate").datepicker("getDate") : null),
maxDate: (input.id == "startDate" ? $("#endDate").datepicker("getDate") : null)
};
}
Can someone help me out in here?
Thanks
回答1:
Try this
1) First get today's and tomorrow's dates.
var today = new Date();
var tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000);
2) Set tomorrow's date as minDate
in start
Date.
minDate: tomorrow
3) When you select a start date, set it as minDate
for end
Date.
onSelect: function (dat, inst) {
$('#end').datepicker('option', 'minDate', dat);
}
The entire thing is going to handle with 3 options in Datepicker.
1. minDate
2. maxDate (if needed)
3. onSelect
$('#end').datepicker();
var today = new Date();
var tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000);
console.log(tomorrow);
$('#start').datepicker({
minDate: tomorrow,
onSelect: function (dat, inst) {
$('#end').datepicker('option', 'minDate', dat);
}
});
JSFiddle
Hope you understand.
来源:https://stackoverflow.com/questions/20371800/datepicker-set-two-dates-with-startdate-tomorrow