我需要禁用jquery datepicker日历中的某一天,所以在函数beforeShowDay中我写道:
beforeShowDay: function(date){
if(parseInt(calMonth) != parseInt(date.getMonth())){
calMonth = date.getMonth();
alert(calMonth + ' - ' + date.getMonth());
}
return {0: true};
}
其中calMonth包含当前月份数字。现在,如果我运行这个,我得到3个警报,按顺序显示: 9-9,10-10和11-11。为什么我有3条消息,虽然它不应该向我显示任何东西(因为当我打开datepicker时,它默认显示当前月份的日历,所以if(parseInt(calMonth) != parseInt(date.getMonth()应该返回false。我还设置了numberOfMonths: 1。
发布于 2014-07-16 21:33:18
也有同样的问题,我是这样解决的:
$("#datepicker").datepicker({ showWeek: true, showOtherMonths : false,
//I'm using onChangeMonthYear to always keep my datepicker month updated
onChangeMonthYear: function(year, month, inst){
$(this).datepicker( "setDate", month + '/1/' + year );
},
beforeShowDay: function(date) {
//Now I can get only the days of the current selected month, and do whatever I want...
if(date.getMonth()==$(this).datepicker('getDate').getMonth())
console.log(date.getDate()+' - '+date.getMonth()+' - '+$(this).datepicker('getDate').getMonth());
//keep returning as usual to the datepicker
return [true, ''];
}
});
希望这会有帮助=)
https://stackoverflow.com/questions/13286443
复制相似问题