以下 javascript 代码创建了一个周历,它为我提供了 startDate 和 endDate: Weekly Calendar Widget
- 我如何调整它以同时为我提供该范围内每个工作日的 MM/DD 值?
例如,我需要将以下变量输出到我的表单中:
- 变量开始日期;(例如 2013 年 11 月 10 日)
变量结束日期;(例如 2013 年 11 月 16 日)
var sun日期; (需要.. 11/10)
- 变量 monDate; (需要.. 11/11)
- 变量 tueDate; (需要.. 11/12)
- var wedDate; (需要.. 11/13)
- var thuDate; (需要.. 11/14)
- var 星期五;(需要.. 11/15)
- 变种日期;(需要.. 11/16)
会不会像..?
var sunDate = endDate - 6(格式化 mm/dd)
这是javascript日历代码:
see link: Weekly Calendar Widget
这是我最终为我工作的更新代码:
<script type="text/javascript">
$(function() {
var startDate;
var endDate;
var monDate;
var tueDate;
var wedDate;
var thuDate;
var friDate;
var satDate;
var sunDate;
var selectCurrentWeek = function() {
window.setTimeout(function () {
$('.week-picker').find('.ui-datepicker-current-day a').addClass('ui-state-active')
}, 1);
}
$('.week-picker').datepicker( {
showOtherMonths: true,
selectOtherMonths: true,
dateFormat: "mm/dd",
firstDay: 1, // Start with Monday
onSelect: function(dateText, inst) {
var date = $(this).datepicker('getDate');
startDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 1);
endDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 7);
monDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 1);
tueDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 2);
wedDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 3);
thuDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 4);
friDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 5);
satDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 6);
sunDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 7);
var dateFormat = inst.settings.dateFormat || $.datepicker._defaults.dateFormat;
$('#startDate').val($.datepicker.formatDate( dateFormat, startDate, inst.settings ));
$('#endDate').val($.datepicker.formatDate( dateFormat, endDate, inst.settings ));
$('#monDate').val($.datepicker.formatDate( dateFormat, monDate, inst.settings ));
$('#tueDate').val($.datepicker.formatDate( dateFormat, tueDate, inst.settings ));
$('#wedDate').val($.datepicker.formatDate( dateFormat, wedDate, inst.settings ));
$('#thuDate').val($.datepicker.formatDate( dateFormat, thuDate, inst.settings ));
$('#friDate').val($.datepicker.formatDate( dateFormat, friDate, inst.settings ));
$('#satDate').val($.datepicker.formatDate( dateFormat, satDate, inst.settings ));
$('#sunDate').val($.datepicker.formatDate( dateFormat, sunDate, inst.settings ));
selectCurrentWeek();
},
beforeShowDay: function(date) {
var cssClass = '';
if(date >= startDate && date <= endDate)
cssClass = 'ui-datepicker-current-day';
return [true, cssClass];
},
onChangeMonthYear: function(year, month, inst) {
selectCurrentWeek();
}
});
$('.week-picker .ui-datepicker-calendar tr').live('mousemove', function() { $(this).find('td a').addClass('ui-state-hover'); });
$('.week-picker .ui-datepicker-calendar tr').live('mouseleave', function() { $(this).find('td a').removeClass('ui-state-hover'); });
});
</script>
然后在我的 HTML 中我使用了:
<thead>
<tr>
<th>Type</th>
<th>Mon<br>
<input disabled id="monDate" size="5" data-mini="true"></th>
<th>Tue<br>
<input disabled id="tueDate" size="5" data-mini="true"></th>
<th>Wed<br>
<input disabled id="wedDate" size="5" data-mini="true"></th>
<th>Thu<br>
<input disabled id="thuDate" size="5" data-mini="true"></th>
<th>Fri<br>
<input disabled id="friDate" size="5" data-mini="true"></th>
<th>Sat<br>
<input disabled id="satDate" size="5" data-mini="true"></th>
<th>Sun<br>
<input disabled id="sunDate" size="5" data-mini="true"></th>
<th>Totals</th>
<th>Description</th>
</tr>
这是我的完整 HTML 页面:https ://dl.dropboxusercontent.com/u/58096637/Timesheet.txt