我已经尝试了几件事来让它工作,但由于我对javascript缺乏了解,没有成功。
我只希望这个小脚本能够完全按照它当前的方式工作,但我希望计算出的天数不包括周末或节假日。有什么帮助吗?
JAVASCRIPT:
$(function() {
$('#from').datepicker({
showOnFocus: false,
showTrigger: '#calImg',
beforeShowDay: $.datepicker.noWeekends,
pickerClass: 'noPrevNext',
numberOfMonths: 1,
dateFormat: 'mm-dd-yy',
minDate: '0',
maxDate: '+1Y',
onSelect: function(dateStr) {
var min = $(this).datepicker('getDate');
$('#to').datepicker('option', 'minDate', min || '0');
datepicked();
}});
$('#to').datepicker({
showOnFocus: false,
showTrigger: '#calImg',
beforeShowDay: $.datepicker.noWeekends,
pickerClass: 'noPrevNext',
numberOfMonths: 1,
dateFormat: 'mm-dd-yy',
minDate: '0',
maxDate: '+1Y',
onSelect: function(dateStr) {
var max = $(this).datepicker('getDate');
$('#from').datepicker('option', 'maxDate', max || '+1Y');
datepicked();
}});
});
var datepicked = function() {
var from = $('#from');
var to = $('#to');
var nights = $('#nights');
var fromDate = from.datepicker('getDate')
var toDate = to.datepicker('getDate')
if (toDate && fromDate) {
var difference = 0;
var oneDay = 1000*60*60*24;
var difference = Math.ceil((toDate.getTime() - fromDate.getTime() + 1) / oneDay);
nights.val(difference);
}
}
HTML:
<table width="100%" border="0" cellpadding="2">
<tr>
<td nowrap>Vacation Request From</td>
<td><input type="text" id="from" name="from" size="28" style="width:194px; /*Tag Style*/" value="" ><div style="display: none;">
<img id="calImg" src="http://www.mywebsite.com/images/calendar-green.gif" alt="Popup" class="trigger"></div> To <input type="text" id="to" name="to" size="28" style="width:194px; /*Tag Style*/" value="" ><div style="display: none;">
<img id="calImg" src="http://www.mywebsite.com/images/calendar-green.gif" alt="Popup" class="trigger">
</div></td>
<td width="1"> </td>
</tr>
<tr>
<td >Total Days Requested: </td>
<td colspan="5"><input type="text" id="nights" name="nights" style="width:50px; /*Tag Style*/" value="" readonly="readonly"></td>
</tr>
<tr>
<td colspan="6"> </td>
</tr>
</table>