2010-09-14 38 views

回答

15

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

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

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

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

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

遗憾,但行数据回[假的, '']; - 显示我的语法错误 – 2011-01-27 14:19:32

+1

@marcin:你可以从该行删除1个返回。 – understack 2011-06-20 11:18:50

1
function LastDayOfMonth(Year, Month) { 
    //set next month first day 
    //substract one day from it.   
    return new Date(new Date(Year, Month+1,1)-1).getDate(); 
} 

这将工作

相关问题