我有一张表格,我想从开始日期和所选天数计算结束日期。
所以过程...... 选择日期 选择开始日期 自动填充enddate =开始日期+天
我有以下工作,但有人知道如何填充计算,所以它有几天,并在计算发生之前输入初始值。
var $title3 = $("#enddate");
$("#startdate").keyup(function () {
$title3.val(this.value);
});
$("#startdate").blur(function () {
$title3.val(this.value);
});
$("#days").keyup(function () {
$title3.val(this.value);
});
$("#days").blur(function () {
$title3.val(this.value);
});
echo'<table width="100%"><tr>
<td class="label"><label for="days">Days:</label></td>
<td class="field">
<select id="days" name="days">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</td>
<td class="status"></td>
</tr>
<tr>
<td class="label"><label for="startdate">Start Date:</label></td>
<td class="field"><input type="text" name="startdate" id="startdate" class="required" readonly="readonly"/></td>
<td class="status"></td>
</tr>
<tr>
<td class="label"><label for="enddate2">End Date:</label></td>
<td class="field"><input type="text" name="enddate2" id="enddate2" class="required" readonly="readonly"/></td>
<td class="status"></td>
</tr></table>';
MOD
这是我提出的解决方案,但需要maxDate才能选择结束日期+ 5天不包括周末。我怎么写这个?
另外,我如何计算出enddate和startdate的2个结果的天数差异,但不包括周末?
var $ac_start_date = '<?php echo $ac_end_date ?>',
$ac_start_date_flip = '<?php echo $ac_end_date_flip ?>',
$ac_start_parsed = Date.parse($ac_start_date),
_today = new Date().getTime();
// For Opera and older winXP IE n such
if (isNaN($ac_start_parsed)) {
$ac_start_parsed = Date.parse($ac_start_date_flip);
}
var _aDayinMS = 1000 * 60 * 60 * 24;
// Calculate the difference in milliseconds
var difference_ms = Math.abs($ac_start_parsed - _today);
// Convert back to days and return
var DAY_DIFFERENCE = Math.round(difference_ms/_aDayinMS);
// do initialization here
$("#startdate").datepicker({
dateFormat: 'dd-mm-yy',
changeMonth: true,
changeYear: true,
yearRange: '0:+100',
onSelect: function( selectedDate ) {
$( "#enddate" ).datepicker( "option", "minDate", selectedDate );
$( "#enddate" ).datepicker( "option", "maxDate", selectedDate + 5days excluding weekends);
},
minDate: '+1d',
maxDate: '+' + (DAY_DIFFERENCE + 1) + 'd'
});
// do initialization here
$("#enddate").datepicker({
dateFormat: 'dd-mm-yy',
changeMonth: true,
changeYear: true,
yearRange: '0:+100'
});
... AHHA
$(".selector").datepicker({ beforeShowDay: $.datepicker.noWeekends })