How to select a week in calendar using js?

Deadly 提交于 2020-04-17 22:47:59

问题


My calendar code:

<script>

  $(document).ready(function() {
 var events = <?php echo json_encode($data) ?>;
    $('#calendar').fullCalendar({
      header: {
        left: 'prev,next',
        center: 'title',
        right: ''
      },
      defaultDate: new Date(),
       // can click day/week names to navigate views
      editable: true,
      eventLimit: true,
      droppable: true,  // allow "more" link when too many events
      dayClick: function(date, jsEvent, view) {

        $("#successModal").modal("show");
        $("#eventDate").val(date.format());

      },
     events    : events
  });

  });

</script>

view page code:

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

These are the code how to select a week in this calendar using js. i have tired using some code but it is not working well


回答1:


This may help you to select whole week in calendar using jQuery

HTML

<div class="row">
    <div class="col-lg-2">
        <input type="week" value="@week" class="form-control" id="Week" />
    </div>
</div>

CSS

/* Week picker */
.datepicker-days > table > tbody > tr:hover {
    background-color: #808080;
}

JavaScript

$(document).ready(function () {
    // Add weekpicker
    $('#Week').datepicker({
       calendarWeeks: true,
       weekStart: 1
    });
});

$('#Week').on('changeDate', function (e) {
    var value = $("#Week").val();
    var year = moment().format('YYYY');
    var week = moment(e.date).format('WW');
    $("#Week").val(year + '-W' + week);
});


来源:https://stackoverflow.com/questions/60574852/how-to-select-a-week-in-calendar-using-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!