两年多前,这个问题在这里被问到,但作为一个菜鸟,我不知道如何使用 Joel Potter 发布的方法作为此 URL 中问题的答案:
Fullcalendar jquery plugin Show years on nextYear buttons
这是我到目前为止在代码中的内容:
$('.fc-button-prevYear span').click(function(){
setYearButtons();
});
$('.fc-button-nextYear span').click(function(){
setYearButtons();
});
function setYearButtons(){
var currentDate = $("#calendar").fullCalendar( 'getDate' );
// I'm not 100% sure on these class names, but you can inspect the dom and figure those out
$(".fc-button-prevYear span").text(currentDate.getYear());
$(".fc-button-nextYear span").text(currentDate.getYear() + 2);
}
如何初始化代码,以便在日历开始时,我将不再看到下一年和上一年箭头,而是在文本中看到下一年和上一年?
此外,计算年份的逻辑似乎有效,但我看到的文本是错误的。例如,如果当前年份是 2012 年(最初我看到箭头按钮,我需要单击上一年或下一年按钮才能更改为文本),当我单击下一年或上一年转到 2013 年时,我的文本按钮显示上一年的 112 和下一年的 114,而不是上一年显示 2012 年,下一年显示 2014 年。
最佳答案
只需将其添加到日历初始化中即可:
$('#calendar').fullCalendar({
theme: false,
header: {
left: 'prev,next today',
center: 'title',
right: 'prevYear, nextYear'
},
buttonText: {
prevYear: parseInt(new Date().getFullYear(), 10) - 1,
nextYear: parseInt(new Date().getFullYear(), 10) + 1
},
viewDisplay: function(view) {
var d = $('#calendar').fullCalendar('getDate');
$(".fc-button-prevYear .fc-button-content").text(parseInt(d.getFullYear(), 10) - 1);
$(".fc-button-nextYear .fc-button-content").text(parseInt(d.getFullYear(), 10) + 1);
}
});
关于jquery - 文本中的全日历去年和明年按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10909564/