5
所以我的問題很簡單。我想要在日期選擇器上啓用特定的日期,例如http://tokenposts.blogspot.fr/2011/05/jquery-datepicker-disable-specific.html,但我只希望在任何月份的最後一天,例如30/06/2012,31/07/2012,...如何僅使用Datepicker Jquery啓用月份的最後幾天?
任何線索?
所以我的問題很簡單。我想要在日期選擇器上啓用特定的日期,例如http://tokenposts.blogspot.fr/2011/05/jquery-datepicker-disable-specific.html,但我只希望在任何月份的最後一天,例如30/06/2012,31/07/2012,...如何僅使用Datepicker Jquery啓用月份的最後幾天?
任何線索?
這是你如何能做到這一點...
獲取最後一天,對於給定的年份和月份:
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, ''];
}
});
非常感謝! – XTN
這工作完美!謝謝 – ScottyG