jquery - 在完整日历中设置自定义隐藏日期

标签 jquery fullcalendar

我们可以通过设置 hiddenDays 属性从 fullcalendar 中隐藏一周中的特定日期。

我需要隐藏一个月中的每隔一个星期六。

有什么可能吗?

最佳答案

您可以使用dayRender回调函数:

This callback lets you modify day cells that are part of the month, basicWeek, and basicDay views. See Available Views.

date is the native Date object for the given day.

检查显示的是否是奇数星期六;为此,您可以获得日期的周数并检查它是否为奇数。

代码:

Date.prototype.getWeekOfMonth = function(exact) {
    var month = this.getMonth()
        , year = this.getFullYear()
        , firstWeekday = new Date(year, month, 1).getDay()
        , lastDateOfMonth = new Date(year, month + 1, 0).getDate()
        , offsetDate = this.getDate() + firstWeekday - 1
        , index = 1 // start index at 0 or 1, your choice
        , weeksInMonth = index + Math.ceil((lastDateOfMonth + firstWeekday - 7) / 7)
        , week = index + Math.floor(offsetDate / 7)
    ;
    if (exact || week < 2 + index) return week;
    return week === weeksInMonth ? index + 5 : week;
};

function isOdd(num) { return num % 2;}

$('#mycalendar').fullCalendar({
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    editable: true,
    events: [{
        title: 'event1',
        start: '2014-01-07'
    }, {
        title: 'event2',
        start: '2014-01-10',
        end: '2013-05-15'
    }, {
        title: 'event3',
        start: '2014-01-13 12:30:00',
        allDay: false // will make the time show
    }],
    dayRender: function (date, cell) {
        if (date.getDay() == 6 && isOdd(date.getWeekOfMonth())) {
            $(cell).addClass('fc-disabled');
        }
    }
});

演示:http://jsfiddle.net/IrvinDominin/cjTF9/

关于jquery - 在完整日历中设置自定义隐藏日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21479552/

相关文章:

javascript - Durandal 模态回调

jquery - 如何在CSS中将背景纹理设置为页面的50%

jquery - 更新分区 :after property using jQuery

javascript - Yii2 如何在 FullCalendar 中设置时间格式?

fullcalendar - 完整日历 - 在没有事件的情况下添加文本

jquery - FullCalendar $ ('td.fc-day' ).鼠标悬停有时会在小月历上得到错误的日期

forms - 浏览器不会提示保存密码

javascript - 如何用按钮制作标题标题

jquery - FullCalendar 资源 View ,更改单元格背景颜色

javascript - 如何在 fullcalendar/jquery 中添加免费时段?