2

我正在开发 ASP.net Webform 应用程序,我需要阻止某些日期和周末作为周五和周六。

以下代码工作正常,它会阻止日期,但默认情况下会阻止周六和周日作为周末,而我需要阻止日历上的所有周五和周六。

我将不胜感激修复此特定代码。我不确定 jQuery Calendar 是否有一个内置属性来指定不同的周末

var holiDays = [[2012, 07, 06, 'New Years Day'], [2012, 07, 14, 'Event XYZ'], [2011, 17, 25, 'Christmas Day']];
$(function () {
    $("#<%=txtBookDate.ClientID %>").datepicker({
        dateFormat: "yy-mm-dd",
        minDate: "-0d",
        maxDate: "+60d",
        beforeShowDay: noWeekendsOrHolidaysOrBlockedDates
    });

    function noWeekendsOrHolidaysOrBlockedDates(date) {
        var noWeekend = jQuery.datepicker.noWeekends(date);
        return noWeekend[0] ? setHoliDays(date) : noWeekend;
    }

    // set holidays function which is configured in beforeShowDay
    function setHoliDays(date) {
        for (i = 0; i < holiDays.length; i++) {
            if (date.getFullYear() == holiDays[i][0]
  && date.getMonth() == holiDays[i][1] - 1
  && date.getDate() == holiDays[i][2]) {
                return [false, 'holiday', holiDays[i][3]];
            }
        }
        return [true, ''];
    }


});
4

1 回答 1

3

您无法访问 jQuery UI 源代码吗?奇怪,因为它是 javascript,并且通常免费提供:

/* Set as beforeShowDay function to prevent selection of weekends.
   @param  date  Date - the date to customise
   @return [boolean, string] - is this date selectable?, what is its CSS class? */
noWeekends: function(date) {
    var day = date.getDay();
    return [(day > 0 && day < 6), ''];
}

看起来很好不可定制,但相对容易重新实现为您自己的功能。

于 2012-06-21T07:40:42.843 回答