주 선택기 [FIDDLE]이 있습니다.로드시 현재 주를 선택할 수 없습니다. 지금까지는 현재 날짜 만 선택했습니다.
또한 이보다 더 쉬운 방법이 있나요?
코드는 다음과 같습니다.
var startDate;
var endDate;
var selectCurrentWeek = function (where) {
console.log(where);
window.setTimeout(function () {
$('.week-picker').find('.ui-datepicker-current-day a').addClass('ui-state-active');
}, 1);
}
$('.week-picker').datepicker({
showOtherMonths: true,
selectOtherMonths: true,
onSelect: function (dateText, inst) {
var date = $(this).datepicker('getDate');
startDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay());
endDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 6);
var dateFormat = inst.settings.dateFormat || $.datepicker._defaults.dateFormat;
$('#startDate').text($.datepicker.formatDate(dateFormat, startDate, inst.settings));
$('#endDate').text($.datepicker.formatDate(dateFormat, endDate, inst.settings));
selectCurrentWeek("week-picker");
},
beforeShowDay: function (date) {
var cssClass = '';
if (date >= startDate && date <= endDate)
cssClass = 'ui-datepicker-current-day';
return [true, cssClass];
},
onChangeMonthYear: function (year, month, inst) {
selectCurrentWeek("change");
}
});
$(document).on('mousemove', '.week-picker .ui-datepicker-calendar tr', function () { $(this).find('td a').addClass('ui-state-hover'); });
$(document).on('mouseleave', '.week-picker .ui-datepicker-calendar tr', function () { $(this).find('td a').removeClass('ui-state-hover'); });
이것은 그것을하는 게토 방식이지만 작동합니다. 기본적으로 당일에 클릭 이벤트를 트리거하려고합니다. 그래서 $ (document) .ready 함수에 추가했습니다.
$(document).ready(function () {
$(".ui-datepicker-today").trigger("click");
});
누구든지 더 나은 솔루션이 있다면 좋을 것입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다