Javascript 如何在jQuery完整日历中选择月份?

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

How to get selected month in jQuery full calendar?

javascriptphpjqueryfullcalendar

提问by Pushparaj

We are using jQuery full calendar for displaying events from database.

我们正在使用 jQuery 完整日历来显示数据库中的事件。

I need to display the events below the calendar according to user selected month onchange. I can get data according to event date but I can't get user selected month in jQuery calendar.

我需要根据用户选择的月份在日历下方显示事件onchange。我可以根据事件日期获取数据,但无法在 jQuery 日历中获取用户选择的月份。

$('#calendar').fullCalendar({
    theme: true,
    header: {

        left: 'today',
        center: 'prevYear,prev,title, next,nextYear',
        right: ' month,agendaWeek,agendaDay'
    },
    buttonText: {
        prevYear: 'Prev'
    },
    editable: false,
    events: [
    <?php foreach ($edumeet_invite_det as $key =>  $edumeet_det): ?> 
    <?php $edumeet_start = $edumeet_det->getFromDate(); ?>
    <?php $edumeet_end = $edumeet_det->getToDate(); ?>
    <?php $title = $edumeet_det->getTitle(); ?> 
        {
            title:'<?php echo $title; ?>',
            start:'<?php echo $edumeet_start ?>',
            end:'<?php echo $edumeet_end ?>',
            allDay: false
        },
    <?php endforeach; ?>
        ],

    eventColor: '#378006',    
});

This is the calendar function I am using, I need to get user selected month onchange. Does anyone have solution for this problem?

这是我正在使用的日历功能,我需要让用户选择月份onchange。有没有人有解决这个问题的方法?

回答by Matt H.

Maybe I don't fully understand your quesiton, but it sounds like you just need to know the current month on screen?

也许我不完全理解你的问题,但听起来你只需要知道屏幕上的当前月份?

FullCalendar has a "getDate" method.

FullCalendar 有一个“getDate”方法。

function getMonth(){
  var date = $("#calendar").fullCalendar('getDate');
  var month_int = date.getMonth();
  //you now have the visible month as an integer from 0-11
}

Sorry if this isn't what you were asking.

对不起,如果这不是你要问的。

回答by user1709374

The function "getView" which might be useful to you:

可能对您有用的函数“getView”:

To get the first day of calendar month:

获取日历月的第一天:

$(cal).fullCalendar('getView').start

$(cal).fullCalendar('getView').start

To get the last day of calendar month:

获取日历月的最后一天:

$(cal).fullCalendar('getView').end

$(cal).fullCalendar('getView').end

To get the first visible day of calendar: (the last few days of previous month)

获取日历的第一个可见日:(上个月的最后几天)

$(cal).fullCalendar('getView').visStart

$(cal).fullCalendar('getView').visStart

To get the last visible day of calendar: (the first few days of next month)

获取日历的最后一天:(下个月的前几天)

$(cal).fullCalendar('getView').visEnd

$(cal).fullCalendar('getView').visEnd

回答by r1si

With last version (2018) need to use this code!

使用最新版本(2018)需要使用此代码!

jQuery("#your_selector").fullCalendar('getDate').month()

回答by Kamlesh

Full Calendar Version - 4

完整日历版本 - 4

<script type="text/javascript">

document.addEventListener('DOMContentLoaded', function() {
    var calendarEl = document.getElementById('calendar');
    var calendar = new FullCalendar.Calendar(calendarEl, {
        ...
        ...
    });

    calendar.render();

    var cdate = calendar.getDate();
    var month_int = cdate.getMonth();
    alert((month_int+1));  // March 2020 month will return 3

});

</script>

This solution worked for me. Happy to help you. Thanks for asking this question.

这个解决方案对我有用。很高兴帮助你。感谢您提出这个问题。

回答by prime

There are ways to get the date and below is one where you can do it when you initialize the calendar, Using that you can get the date , month and year separately.

有多种方法可以获取日期,下面是一种方法you can do it when you initialize the calendar,使用它您可以分别获取日期、月份和年份。

 $('#calendar').fullCalendar({

    dayClick: function(date, jsEvent, view) { 
        alert('Clicked on: ' + date.getDate()+"/"+date.getMonth()+"/"+date.getFullYear());  
    },

});