【发布时间】:2012-07-04 13:50:59
【问题描述】:
所以我的问题很简单。我想在日期选择器上启用特定日期,例如http://tokenposts.blogspot.fr/2011/05/jquery-datepicker-disable-specific.html,但我只想要任何一个月的最后一天,例如 30/06/2012、31/07/2012,...
有什么线索吗?
【问题讨论】:
标签: javascript jquery jquery-ui datepicker
所以我的问题很简单。我想在日期选择器上启用特定日期,例如http://tokenposts.blogspot.fr/2011/05/jquery-datepicker-disable-specific.html,但我只想要任何一个月的最后一天,例如 30/06/2012、31/07/2012,...
有什么线索吗?
【问题讨论】:
标签: javascript jquery jquery-ui datepicker
你可以这样做......
获取给定年份和月份的最后一天:
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, ''];
}
});
【讨论】: