如何仅禁用上个月的日期

How do disable only dates from previeous month

我有一个简单的部分,其中我使用完整日历 API 为我的用户显示日历,我只想禁用上个月的日期。

JSFIDDLE demo

预期结果

这是我迄今为止使用完整日历文档尝试过的内容 HTML

<div id="calendar"></div>

JS

$('#calendar').fullCalendar({
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
             selectable: true,
                  selectAllow: function(selectInfo) {
                      console.log(selectInfo);
                    return moment().diff(selectInfo.start) <= 0
                  },  
    // set source and define start and end params
    events: [
        {
            id: "1",
            title: "First event",
            start: "20120-03-26 13:00:00",
            end: "2020-03-26 15:00:00",
            className: 'available'
        },
        {
            id: "2",
            title: "Second event",
            start: "2020-03-29 18:00:00",
            end: "2020-03-29 20:00:00",

        }
    ],

});

NOTE: am using full calendar v4

不幸的是,我的解决方案禁用了所有过去的日期,但我只想禁用过去一个月的日期

我需要做什么才能达到我想要的效果?

您可以轻松地使用 momentJS 找到当前月份的开始,并将所选日期与该日期进行比较。

selectAllow: function(selectInfo) {
  var ms = moment().startOf("month");
  return ms.isSameOrBefore(selectInfo.start);
}

演示:https://codepen.io/ADyson82/pen/yLNRWwZ

有关详细信息,请参阅 https://momentjs.com/docs/#/manipulating/start-of/

如果您不想在比当前日期早的日子添加计划,那么您可以这样编码:

selectable: true,
selectAllow: function(selectInfo) {
  var ms = moment(new Date()).subtract(1, 'day');
  return ms.isSameOrBefore(selectInfo.start);
},