javascript - jQuery 完整日历 : set a different color to each event from front-end

标签 javascript jquery colors fullcalendar

这就是我使用插件的方式:

jQuery( document ).ready( function() {
    jQuery('#booking-calendar').fullCalendar({
        header: {
            left: 'prev,next',
            center: 'title',
            right: 'month,basicWeek,basicDay'
        },
        editable: true,
        events: '<?php echo get_template_directory_uri() ?>/bookings-feed.php'
    });

    jQuery( '#apartment-selector' ).change( function() {
        apartment = jQuery( this ).val()
        jQuery('#booking-calendar').fullCalendar( 'removeEvents' )
        jQuery('#booking-calendar').fullCalendar( 'addEventSource',  {
            url: '<?php echo get_template_directory_uri() ?>/bookings-feed.php',
            type: 'POST',
            data: {
                apartment : apartment
            }
        })
    })
})

这是它的样子:

enter image description here

如您所见,跟踪事件的开始和结束时间有点困难,因此我考虑更改每个事件的颜色。

这里的问题是每个事件可能会在不同的周内拆分(如示例中所示)并且每周都有不同的 DOM 事件(这是有道理的)并且它们没有任何相关的类,

如何为每个事件涂上不同的颜色?

最佳答案

要对每个事件进行不同的着色,您可以采用几种方法来解决您的问题。

  1. 更新事件源“/bookings-feed.php”并向事件对象添加颜色(背景和边框)、backgroundColor、textColor 或 borderColor http://arshaw.com/fullcalendar/docs/event_data/Event_Object/ .

     events: [{
         title  : 'event1',
         start  : '2010-01-01',
         color  : '#000'
     }]
    
  2. 分离并更新事件源以使用 eventSources。这允许您按颜色和文本颜色对事件进行分组。 http://arshaw.com/fullcalendar/docs/event_data/events_array/ .

 $('#calendar').fullCalendar({
    eventSources: [
        // your event source
        {
            events: [ // put the array in the `events` property
                {
                    title  : 'event1',
                    start  : '2010-01-01'
                },
                {
                    title  : 'event2',
                    start  : '2010-01-05',
                    end    : '2010-01-07'
                },
                {
                    title  : 'event3',
                    start  : '2010-01-09 12:30:00',
                }
            ],
            color: 'black',     // an option!
            textColor: 'yellow' // an option!
        }
        // any other event sources...
    ]
});

关于javascript - jQuery 完整日历 : set a different color to each event from front-end,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18619903/

相关文章:

javascript - 选择选项在提交/刷新后保持选中状态

C - 如何读取屏幕像素的颜色(快速)? (在 Windows 中)

javascript - JS : need a css color code based on a string

javascript - javascript 中的 Jinja 模板

javascript - JQuery - 触发对 div 的调用变得可见

javascript - 缩进jqgrid组的子元素

javascript - @typescript-eslint/no-unsafe-assignment : Unsafe assignment of an any value

jquery - Chrome 和 Firefox 中禁用表单输入的工作方式不同

javascript - jQuery 链接没有按预期工作

css - 如何知道两个十六进制颜色代码之间的偏移量