gpt4 book ai didi

javascript - Fullcalendar 5 月和 6 月均显示值 4

转载 作者:行者123 更新时间:2023-12-02 14:37:10 25 4
gpt4 key购买 nike

我们遇到了全日历问题 http://fullcalendar.io/ 。如果我们点击下一步,五月和六月都显示第四个月。单击标题中的下一个或上一个按钮。

我们是否遗漏了什么?

代码行:alert('viewRender View 月份: ' + view.start._d.getMonth());

fiddle 链接 https://jsfiddle.net/sudiptabanerjee/z7La379f/2/

JS:

 $(document).ready(function () {

$('#calendar').fullCalendar({
// defaultDate: '2016-06-12',
editable: true,
eventLimit: true, // allow "more" link when too many events
viewRender: function (view, element) {

alert('viewRender view month: ' + view.start._d.getMonth());
},
events: [
{
title: 'All Day Event',
start: '2016-06-01'
},
{
title: 'Long Event',
start: '2016-06-07',
end: '2016-06-10'
},
{
id: 999,
title: 'Repeating Event',
start: '2016-06-09T16:00:00'
},
{
id: 999,
title: 'Repeating Event',
start: '2016-06-16T16:00:00'
},
{
title: 'Conference',
start: '2016-06-11',
end: '2016-06-13'
},
{
title: 'Meeting',
start: '2016-06-12T10:30:00',
end: '2016-06-12T12:30:00'
},
{
title: 'Lunch',
start: '2016-06-12T12:00:00'
},
{
title: 'Meeting',
start: '2016-06-12T14:30:00'
},
{
title: 'Happy Hour',
start: '2016-06-12T17:30:00'
},
{
title: 'Dinner',
start: '2016-06-12T20:00:00'
},
{
title: 'Birthday Party',
start: '2016-06-13T07:00:00'
},
{
title: 'Click for Google',
url: 'http://google.com/',
start: '2016-06-28'
}
]
});

});

HTML:

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

CSS:

body {
margin: 40px 10px;
padding: 0;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
font-size: 14px;
background-color:#fff;
}

#calendar {
max-width: 600px;
margin: 0 auto;
}

提前致谢。

最佳答案

JS中,月份从0开始,

0 - Jan
1 - Feb
2 - Mar
3 - Apr
4 - May
5 - June

当您在月 View 中导航到 5 月时,该月的第一天是 1(即 5 月 1 日)对于 6 月,该月的第一天是 29(即 5 月 29 日),两者都是 5 月

五月的数字是 4

它显示了正确的月份,

编辑 https://jsfiddle.net/z7La379f/3/

如果您想获取当前 View 的月份,您可以这样做

viewRender: function (view, element) {

// alert('viewRender element: '+element.start._d.getMonth());
// alert('viewRender view month: ' + view.start._d.getMonth());
var dt=moment(view.start).add(10,'days');
var mnth =moment(dt).month();
alert(mnth);
},

关于javascript - Fullcalendar 5 月和 6 月均显示值 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37360661/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com