【发布时间】:2016-10-23 21:43:50
【问题描述】:
您好,我正在尝试创建一个预订表单,用户只能在其中选择 1 到 14 天(从当前日期 +1)。我遇到的问题是 EndDate(此处为#til)设置为从今天开始的 14 天。因此,如果我在 StartDate(此处为 #fra)继续一个月,我无法在 EndDate 中选择任何内容。
如何使 EndDate 相对于 StartDate 设置?
$( function valgavdato() {
var dateFormat = "mm/dd/yy",
from = $( "#fra" )
.datepicker({
minDate: '0+',
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1
})
.on( "change", function() {
to.datepicker( "option", "minDate", getDate( this ) );
}),
to = $( "#til" ).datepicker({
maxDate: '14+',
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1
})
.on( "change", function() {
from.datepicker( "option", "maxDate", getDate( this ) );
});
function getDate( element ) {
var date;
try {
date = $.datepicker.parseDate( dateFormat, element.value );
} catch( error ) {
date = null;
}
return date;
}
} );
【问题讨论】:
-
使用选择事件更新其他日期选择器
标签: jquery jquery-ui datepicker jquery-ui-datepicker