我下面这个的jsfiddle能够突出和日期选择器选择整个星期。
我已经定制它通过改变使用jQuery 1.9工作.live()
来.on()
下面是编辑的jsfiddle 。 它工作正常,但在其当前状态的一周只强调一次约会的用户点击。
我想实现的是要突出(并填充的startDate和结束日期瓦尔日期)到当前日期启动时自动属于不点击当前日期的一周。 我曾尝试以下,但它似乎不工作
var currentDate = $(".week-picker").datepicker("getDate");
var onSelectFunction = $(".week-picker").datepicker("option","onSelect");
var format = $(".week-picker").datepicker( "option", "dateFormat" );
var currDate = $.datepicker.formatDate(format,currentDate)
onSelectFunction( currDate );
有什么建议?
试试这个
$(function () {
var startDate;
var endDate;
var selectCurrentWeek = function () {
window.setTimeout(function () {
$('.week-picker').find('.ui-datepicker-current-day a').addClass('ui-state-active')
}, 1);
}
var $weekPicker = $('.week-picker');
function updateWeekStartEnd() {
var date = $weekPicker.datepicker('getDate') || new Date();
startDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay());
endDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 6);
}
updateWeekStartEnd();
function updateDateText(inst) {
var dateFormat = inst != 'start' && inst.settings.dateFormat ? inst.settings.dateFormat : $.datepicker._defaults.dateFormat;
console.log( dateFormat)
$('#startDate').text($.datepicker.formatDate(dateFormat, startDate, inst.settings));
$('#endDate').text($.datepicker.formatDate(dateFormat, endDate, inst.settings));
}
updateDateText('start');
$weekPicker.datepicker({
showOtherMonths: true,
selectOtherMonths: true,
onSelect: function (dateText, inst) {
updateWeekStartEnd();
updateDateText(inst);
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();
}
});
selectCurrentWeek();
$('.week-picker .ui-datepicker-calendar tr').on('mousemove', function () {
$(this).find('td a').addClass('ui-state-hover');
});
$('.week-picker .ui-datepicker-calendar tr').on('mouseleave', function () {
$(this).find('td a').removeClass('ui-state-hover');
});
});
DEMO: http://jsfiddle.net/eFzG4/
您还可以触发点击当前日期
$(".ui-datepicker-current-day").click();