如何在Check Out的值中显示Check In加1的jquery datepicker值?

时间:2016-02-04 04:37:29

标签: javascript jquery html css datepicker

我的代码就像是:

jQuery("#datepicker_checkin").datepicker({ 
    minDate: 0, 
    numberOfMonths: 2,
    showButtonPanel: true,
    changeMonth: true,
    changeYear: true,
    dateFormat: "yy-mm-dd"
}); 
jQuery("#datepicker_checkout").datepicker({ 
    beforeShow : function()
    {
        jQuery( this ).datepicker('option','minDate', jQuery('#datepicker_checkin').val() );
    } , 
    numberOfMonths: 2,
    showButtonPanel: true,
    changeMonth: true,
    changeYear: true,
    dateFormat: "yy-mm-dd"
}); 
jQuery("#datepicker_checkin").on('change', function() {
    jQuery("#datepicker_checkout").val(jQuery('#datepicker_checkin').val());
    jQuery("#datepicker_checkout").datepicker({ 
        beforeShow : function()
        {
            jQuery( this ).datepicker('option','minDate', jQuery('#datepicker_checkin').val() );
        } , 
        numberOfMonths: 2,
        showButtonPanel: true,
        changeMonth: true,
        changeYear: true,
        dateFormat: "yy-mm-dd"
    }); 
});

演示是这样的:DEMO

我这样描述:

如果我选择签入的文本字段,则签出的文本字段将显示签出值+ 1

例如:

如果入住= 2016-02-26然后退房= 2016-02-27

任何帮助非常感谢

干杯

2 个答案:

答案 0 :(得分:1)

试试此代码

$(function() {
  $( "#check-in" ).datepicker({
    numberOfMonths: 2,
    showButtonPanel: true,
    changeMonth: true,
    changeYear: true,
    dateFormat: "yy-mm-dd",
    onSelect: function() {
        var checkOutDate = $(this).datepicker('getDate');
        checkOutDate.setDate(checkOutDate.getDate() + 1);
        $( "#check-out" ).datepicker( "option", "minDate", checkOutDate );
        $('#check-out').datepicker('setDate', checkOutDate);
    }
  });

  $( "#check-out" ).datepicker({
    numberOfMonths: 2,
    showButtonPanel: true,
    changeMonth: true,
    changeYear: true,
    dateFormat: "yy-mm-dd"
  });
});

答案 1 :(得分:0)

 $('.pickupDate').change(function() {
  var date2 = $('.pickupDate').datepicker('getDate', '+1d'); 
  date2.setDate(date2.getDate()+1); 
  $('.dropoffDate').datepicker('setDate', date2);
});

根据示例添加+ 1d希望这对您有帮助。