我有2个针对酒店预订的日期选择器,在日期范围的表单中有2个文本字段。如果有人选择带有第一个日期选择器的日期,则第二个自动填充文本字段2中的相同日期。如何更改脚本以填写第二天的日期而不是同一日期?
我的代码
$(function() {
var dates = $( "#from, #to" ).datepicker({
showOn: "both",
buttonImage: "fileadmin/template/datepicker/img/kalender.png",
buttonImageOnly: true,
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onSelect: function( selectedDate ) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" );
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
答案 0 :(得分:3)
为onSelect
事件尝试此代码:
onSelect: function(selectedDate) {
var option = this.id == "from" ? "minDate" : "maxDate";
var date = new Date($(this).datepicker('getDate'));
date.setDate(date.getDate() + 1);
dates.not(this).datepicker("option", option, date);
}
答案 1 :(得分:0)
$(function() {
var dates = $("#from, #to").datepicker({
showOn: "both",
buttonImage: "fileadmin/template/datepicker/img/kalender.png",
buttonImageOnly: true,
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onSelect: function(dateText, inst) {
var option = this.id == "from" ? "minDate" : "maxDate",
actualDate = new Date(dateText);
var newDate = new Date(actualDate.getFullYear(), actualDate.getMonth(), actualDate.getDate() + 1);
dates.not(this).datepicker("option", option, newDate);
}
});
});
<强> DEMO 强>