首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >datepicker beforeShowDay退货3个月

datepicker beforeShowDay退货3个月
EN

Stack Overflow用户
提问于 2012-11-08 17:46:59
回答 1查看 848关注 0票数 1

我需要禁用jquery datepicker日历中的某一天,所以在函数beforeShowDay中我写道:

代码语言:javascript
运行
复制
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。

EN

回答 1

Stack Overflow用户

发布于 2014-07-16 21:33:18

也有同样的问题,我是这样解决的:

代码语言:javascript
运行
复制
$("#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, ''];
    } 
});

希望这会有帮助=)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13286443

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档