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 );
}
});    
4

2 回答 2

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);
}
于 2012-05-09T17:08:03.380 回答
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);
        }
    });
});

演示

于 2012-05-09T17:09:53.710 回答