var dates1 = $( "#stime, #etime" ).datetimepicker({ dateFormat: 'yy-mm-dd', timeFormat:'HH:mm:ss', //minDate: -7, maxDate: +0, showTime: true, onSelect: function( selectedDate ) { var option = this.id == "stime" ? "maxDate" : "minDate", instance = $( this ).data( "datepicker" ), date = $.datepicker.parseDate( instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings ); var curdate = date.getDate(); // 控制日期之间相隔天数,1为一天 curdate = this.id == "etime" ? curdate - 7 : curdate + 7; var cur_date=new Date().getDate(); if(cur_date>=curdate - 7){ curdate=cur_date; } date.setDate(curdate); dates1.not( this ).datetimepicker( "option", option, date ); if(option=='maxDate'){ dates1.not( this ).datetimepicker( "option", "minDate", $(this).val() ); }else{ dates1.not( this ).datetimepicker( "option", "maxDate", $(this).val() ); } } });