我在两个字段( book_from和book_to )中使用Jquery日期选择器进行预订。
当我关注book_from时,只有小于book_to的日期和大于或等于今天日期的日期必须显示在book_from的日期选择器中。
ie
如果book_from = null和book_to=2012-04-10
然后,book_from日期选择器只应大于今天的日期(2012-03-18),小于2012-04-10 (book_to) (甚至不是2012-04-10)
如果我专注于book_to,那么在book_to的日期选择器中,只有日期大于今天的日期+大于book_from日期
ie
如果book_from = 2012-04-05
然后,book_to日期选择器只显示大于今天的日期(2012-03-18)和大于2012-04-05 (甚至不是2012-04-05)
如果有人知道怎么做请帮助我。
发布于 2012-03-20 11:03:50
在谷歌上搜索了许多小时之后,我终于找到了解决方案,它是用于预订的日期范围数据报警器:).I不仅仅是为了解释我的问题。这是解决办法
$('#book_from, #book_to').datepicker({
minDate: 0,
changeMonth: true,
changeYear: true,
beforeShow: customRange,
dateFormat: "yy-mm-dd"
});
function customRange(input) {
if (input.id == 'book_to') {
var minDate = new Date($('#book_from').val());
minDate.setDate(minDate.getDate() + 1)
return {
minDate: minDate
};
}
else if(input.id == 'book_from') {
var maxDate = new Date($('#book_to').val());
maxDate.setDate(maxDate.getDate()-1)
return {
maxDate: maxDate
};
}
return {}
}https://stackoverflow.com/questions/9757637
复制相似问题