javascript - 将边框样式添加到完整日历中的事件

标签 javascript css fullcalendar fullcalendar-4

enter image description here我只想将边框样式添加到其中一个事件,而不是完整日历中的所有事件。有什么帮助吗? 更改就像想要为完整日历的事件添加边框样式。更改就像想要为完整日历的事件添加边框样式。

Only add the border style to the single event for the calendar.
 Only add the border style to the single event for the calendar.
<script>
  document.addEventListener('DOMContentLoaded', function() {
    var calendarEl = document.getElementById('calendar');

    var calendar = new FullCalendar.Calendar(calendarEl, {
      plugins: [ 'interaction', 'resourceDayGrid', 'resourceTimeGrid' ],
      defaultView: 'resourceTimeGridDay',
      defaultDate: '2019-08-07',
      editable: true,
      selectable: true,
      eventLimit: true, // allow "more" link when too many events
      header: {
        left: 'prev,next today',
        center: 'title',
        right: 
  'resourceTimeGridDay,resourceTimeGridTwoDay,timeGridWeek,dayGridMonth'
      },
      views: {
        resourceTimeGridTwoDay: {
          type: 'resourceTimeGrid',
          duration: { days: 2 },
          buttonText: '2 days',
        }
      },

      //// uncomment this line to hide the all-day slot
      //allDaySlot: false,

      resources: [
        { id: 'a', title: 'Room A', eventColor: 'pink' },
        { id: 'b', title: 'Room B', eventColor: 'green' },
        { id: 'c', title: 'Room C', eventColor: 'orange' },
        { id: 'd', title: 'Room D', eventColor: 'red' }
      ],
      events: [
        { id: '1', resourceId: 'a', start: '2019-08-06', end: '2019-08- 
     08', title: 'event 1' },
        { id: '2', resourceId: 'a', start: '2019-08-07T09:00:00', end: 
'2019-08-07T14:00:00', title: 'event 2' },
        { id: '3', resourceId: 'b', start: '2019-08-07T12:00:00', end: 
'2019-08-08T06:00:00', title: 'event 3' },
        { id: '4', resourceId: 'c', start: '2019-08-07T07:30:00', end: 
'2019-08-07T09:30:00', title: 'event 4' },
        { id: '5', resourceId: 'd', start: '2019-08-07T10:00:00', end: 
'2019-08-07T15:00:00', title: 'event 5' }
      ],

      select: function(arg) {
        console.log(
          'select',
          arg.startStr,
          arg.endStr,
          arg.resource ? arg.resource.id : '(no resource)'
        );
      },
      dateClick: function(arg) {
        console.log(
          'dateClick',
          arg.date,
          arg.resource ? arg.resource.id : '(no resource)'
        );
      }
    });

    calendar.render();
  });

</script>
<style>
    #a {
        border-color: 5px dashed yellow;
    }
  body {
    margin: 0;
    padding: 0;
    font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
    font-size: 14px;
  }

  #calendar {
    max-width: 900px;
    margin: 50px auto;
  }

</style>
</head>
<body>

  <div id='calendar'></div>

</body>
</html>

仅将边框样式添加到日历的单个事件。

最佳答案

您可以在事件中使用“borderColor”选项,如下所示:

events: [
        { id: '1', resourceId: 'a', start: '2019-08-06', end: '2019-08- 
     08', title: 'event 1', borderColor: '#0000ff' },
        { id: '2', resourceId: 'a', start: '2019-08-07T09:00:00', end: 
'2019-08-07T14:00:00', title: 'event 2' },
        { id: '3', resourceId: 'b', start: '2019-08-07T12:00:00', end: 
'2019-08-08T06:00:00', title: 'event 3' },
        { id: '4', resourceId: 'c', start: '2019-08-07T07:30:00', end: 
'2019-08-07T09:30:00', title: 'event 4' },
        { id: '5', resourceId: 'd', start: '2019-08-07T10:00:00', end: 
'2019-08-07T15:00:00', title: 'event 5' }
      ]

请注意,我在第一个事件中添加了“borderColor”选项。

您可以使用 eventRender 应用边框样式,如下所示:

eventRender: function (info) {
  var eventId = info.event.id;
  if (eventId == '1')
    {
      $(info.el).css("border-style", "dashed");
      $(info.el).css("border-color", "#ffff00");
    }
}

关于javascript - 将边框样式添加到完整日历中的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59067208/

相关文章:

jquery - 渲染后更改 Fullcalendar 事件源

javascript - 将十进制数(作为字符串) chop 到固定的位数

php - 解决多个 jQuery 文件之间的冲突

jquery - 在 CSS 中选择子级的父级

javascript - 我的菜单不再显示汉堡图标

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

javascript - Internet Explorer 延迟启动 AJAX 调用

Javascript 在同一台机器上给出不同的时区

javascript - CSS 突出显示选定的按钮

json - FullCalendar - 向 Event 对象添加新属性