jQuery 从当前月份中删除过去的日期和下个月的日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7628040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 00:04:51  来源:igfitidea点击:

Remove past dates and next months dates from the current month

jqueryfullcalendar

提问by rubyist

Is it possible to remove the past dates and next month's dates from the fullcalendar? So for the current month it should display only current dates and days.

是否可以从完整日历中删除过去的日期和下个月的日期?所以对于当月,它应该只显示当前的日期和天数。

回答by Bascht

You could try skipping the events in the eventRender() method:

您可以尝试跳过 eventRender() 方法中的事件:

eventRender: function(event, element, view)
{
   if(event.start.getMonth() !== view.start.getMonth()) { return false; }
}

回答by David Webster

The grid cells for the next and previous month have the class "fc-other-month", so you can target them that way:

下个月和上个月的网格单元具有“fc-other-month”类,因此您可以通过这种方式定位它们:

e.g.: The hide the day numbers, add the CSS:

例如:隐藏天数,添加 CSS:

.fc-other-month .fc-day-number { display:none;}

or run this JavaScript:

或运行此 JavaScript:

$(".fc-other-month .fc-day-number").hide()

回答by Mohamed Alikhan

Try this!

尝试这个!

$('.fc-other-month').html('');

This works for me!

这对我有用!

回答by Kihats

Add this setting showNonCurrentDates: false. With this setting, dates and events that do not belong to the current month will not be shown.

添加此设置showNonCurrentDates: false。使用此设置,不属于当月的日期和事件将不会显示。

$('#calendarId').fullCalendar({
     // Other settings
     showNonCurrentDates: false            
});

回答by ZettaGeek

None of the solutions provided on this answer properly solve the problem with the current version of FullCalendar. Using Bascht's answer as a starting point, I've updated his approach to use the current FullCalendar APIs. Below is working example code that will accomplish this task:

此答案中提供的解决方案均未正确解决当前版本的 FullCalendar 的问题。使用 Bascht 的答案作为起点,我更新了他的方法以使用当前的 FullCalendar API。以下是将完成此任务的工作示例代码:

eventRender: function (event, element) {
    var eventDate = event.start;
    var calendarDate = $('#activitiesCalendar').fullCalendar('getDate');
    if (eventDate.get('month') !== calendarDate.get('month')) {
        return false;
    }
}

回答by jettpleyn

for version 2.0 or higher:

对于 2.0 或更高版本:

eventRender: function (event, element, view) {
   if(event.start._d.getMonth() !== $('calendar').fullCalendar('getDate')._d.getMonth()) { 
      return false; 
    }
}

// if you want to remove other month's days from view add to css:
    .fcc-other-month { 
        visibility:hidden;
     }

回答by Roberto Flores

Try using weekMode: http://fullcalendar.io/docs/display/weekMode/.

尝试使用 weekMode:http://fullcalendar.io/docs/display/weekMode/ 。

weekMode: 'liquid', or `weekMode: 'variable',`

Hope it helps

希望能帮助到你

回答by Ryan Barkley

For newer version of FullCalendar plugin, the following works utilizing Moment.js helper functions:

对于较新版本的 FullCalendar 插件,以下工作使用 Moment.js 辅助函数:

eventRender: function(event, element, view){ var evStart = moment(view.intervalStart).subtract(1, 'days'); var evEnd = moment(view.intervalEnd).subtract(1, 'days'); if (!event.start.isAfter(evStart) || event.start.isAfter(evEnd)) { return false; } },

eventRender: function(event, element, view){ var evStart = moment(view.intervalStart).subtract(1, 'days'); var evEnd = moment(view.intervalEnd).subtract(1, 'days'); if (!event.start.isAfter(evStart) || event.start.isAfter(evEnd)) { return false; } },

回答by Varun Sreedharan

Using event render and a callback function solved my issue .Perfectly hiding previous and next month events from current view

使用事件渲染和回调函数解决了我的问题。从当前视图中完美隐藏上个月和下个月的事件

eventRender: function(event, element, view) {
                        if (view.name == "month") {
                            if (event.start._i.split("-")[1] != getMonthFromString(view.title.split(" ")[0])) {
                                return false;
                            }
                        }
                    }

function getMonthFromString(mon) {
            var d = Date.parse(mon + "1, 2016");
            if (!isNaN(d))
                return new Date(d).getMonth() + 1;
            return -1;
        }

Hope it helps

希望能帮助到你

回答by mudassar031

$('.fc-other-month').html('');

and for disabling other month:

并禁用其他月份:

$(".fc-other-month").addClass('fc-state-disabled');