jQuery UI DatePicker - 禁用除日期之外的所有日期 [英] jQuery UI DatePicker - Disable all days except last day of month

查看:92
本文介绍了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, ''];
    }
});

这篇关于jQuery UI DatePicker - 禁用除日期之外的所有日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆