首页 > 解决方案 > fullcalender 在添加有效范围时跳过一个月

问题描述

我想在 fullcalender 中从当前日期跳过 10 天,它工作正常,但是当我点击下个月时,它会从 1 月直接进入 3 月并跳过 2 月。

这是导致问题的代码和行:start: nowDate.setDate(nowDate.getDate() +10

<script type="text/javascript">
// jQuery(document).ready(function($){
  document.addEventListener('DOMContentLoaded', function() {
    var scheduled_occasionsEl = document.getElementById('occ');

    var scheduled_occasions = new FullCalendar.Calendar(scheduled_occasionsEl, {
      // initialDate: '2020-09-12',
      // editable: true,
      selectable: true,
      // businessHours: true,
      dayMaxEvents: true, // allow "more" link when too many events
      events: <?php echo json_encode($calendar_events)?>,
      validRange: function(nowDate){
    return {start:  nowDate.setDate(nowDate.getDate() +10)} //to prevent anterior dates
},
    });
    scheduled_occasions.render();
  });
// });
</script>

标签: jquerydateskip

解决方案


我使用此处给出的文档链接https://fullcalendar.io/docs/visibleRange修复了没有时刻 js

validRange: function(nowDate){
 var startDate = new Date(nowDate.valueOf());
 startDate.setDate(startDate.getDate() + 10); 

   return {start:  startDate} //to prevent anterior dates
},

推荐阅读