【问题标题】:How do I only enable the last days of months with Datepicker Jquery?如何仅使用 Datepicker Jquery 启用月份的最后几天?
【发布时间】: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


    【解决方案1】:

    你可以这样做......

    获取给定年份和月份的最后一天:

    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, ''];
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多