2010-09-14 63 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(); 
} 

這將工作

相關問題