我如何仅使用Datepicker Jquery启用几个月的最后几天?

时间:2012-07-04 13:51:00

标签: javascript jquery jquery-ui datepicker

所以我的问题非常简单。我想在datepicker上启用特定日期,例如http://tokenposts.blogspot.fr/2011/05/jquery-datepicker-disable-specific.html,但我只想要任何月份的最后一天,例如30/06 / 2012,31 / 07/2012,...

有任何线索吗?

1 个答案:

答案 0 :(得分:3)

这就是你可以做到的......

获取特定年份和月份的最后一天:

function getLastDayOfYearAndMonth(year, month)
{
    return(new Date((new Date(year, month + 1, 1)) - 1)).getDate();
}

如果日期是最后一个月的日期,请查看beforeShowDay事件:

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

        return [false, ''];
    }
});