jQuery 在 FullCalendar 中更改日期背景颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17920017/
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-26 20:12:32  来源:igfitidea点击:

Change the day background color in FullCalendar

javascriptjqueryasp.netfullcalendar

提问by Bishan

I'm using FullCalendarin my asp.net application. I need to change the daybackground color.

我在我的 asp.net 应用程序中使用FullCalendar。我需要更改一天的背景颜色。

What i have tried so far :

到目前为止我尝试过的:

dayRender: function (date, cell) {

    var today = new Date();
    var end = new Date();
    end.setDate(today.getDate()+7);

    if (date.getDate() === today.getDate()) {
        cell.css("background-color", "red");
    }

    var start = new Date();
    start.setDate(today.getDate()+1);


    while(start <= end){

      //alert(start + "\n" + tomorrow);
        if(start.getDate() == date.getDate()){
            cell.css("background-color", "yellow");
        }

       var newDate = start.setDate(start.getDate() + 1);
       start = new Date(newDate);
    }        
}

This change background color of whole days. Demo

这改变了一整天的背景颜色。演示

But my need is to change the background color of days, 7 days onward from current date.

但我需要更改天的背景颜色,从当前日期起 7 天。

Example

例子

Today is 2013-July-29. I need to change the background color of below days.

今天是 2013 年 7 月 29 日。我需要更改以下几天的背景颜色。

2013-July-30
2013-July-31
2013-August-01
2013-August-02
2013-August-03
2013-August-04
2013-August-05

How can i do this ?

我怎样才能做到这一点 ?

回答by Regin Larsen

You can do it like this:

你可以这样做:

dayRender: function (date, cell) {

    var today = new Date();
    var end = new Date();
    end.setDate(today.getDate()+7);

    if (date.getDate() === today.getDate()) {
        cell.css("background-color", "red");
    }

    if(date > today && date <= end) {
        cell.css("background-color", "yellow");
    }

}   

http://jsfiddle.net/z8Jfx/7/

http://jsfiddle.net/z8Jfx/7/

回答by Kinle

dayRender : function(date, cell) {
                            var idx = null;
                            var today = new Date().toDateString();
                            var ddate = date.toDate().toDateString();

                            if (ddate == today) {
                                idx = cell.index() + 1;
                                cell.css("background-color", "azure");
                                $(
                                        ".fc-time-grid .fc-bg table tbody tr td:nth-child("
                                                + idx + ")").css(
                                        "background-color", "azure");

                            }

                        }