jQuery UI DatePicker - 禁用除日期之外的所有日期

jQuery UI DatePicker  - 禁用除日期之外的所有日期

问题描述:

我正在尝试使用jquery UI datepicker来显示只有最后一天的日历可选择的日历。

I'm trying to use the jquery UI datepicker to show a calendar with only the last day of the month selectable.

我已成功使用beforeShowDay活动来禁用一周中的几天,但不知道如何使用此功能来禁用除本月最后一天之外的所有内容。 / p>

I've successfully used the beforeShowDay event to disable days of the week but not sure how I'd use this to disable everything but the last day of the month.

beforeShowDay被调用在日历上显示的每个日期。当BeforeShowDay被调用之前,您需要确定传递给它的日期是否是该月的最后一天。

beforeShowDay is called for every date shown on the calender. When beforeShowDay is called, you need to determine if the date passed to it is the last day of the month.

以下JScript将返回给定年份和月份的月份的最后一天。

The following JScript will return the last day of the month for a given year and month.

function LastDayOfMonth(Year, Month)
{
    return(new Date((new Date(Year, Month+1,1))-1)).getDate();
}

使用以下代码确定beforeShowDay的日期是月的最后一个:

Use the following code to determine if the beforeShowDay's date is the last of the month:

$('.selector').datepicker({
    beforeShowDay: function (date) {
        //getDate() returns the day (0-31)
        if (date.getDate() == LastDayOfMonth(date.getFullYear(),date.getMonth())) {
            return [true, ''];
        }
        return [false, ''];
    }
});