Javascript 完整日历跳转到日期
如何制作自定义按钮以跳转到日期功能Javascript 完整日历跳转到日期,javascript,fullcalendar,Javascript,Fullcalendar,如何制作自定义按钮以跳转到日期功能 $('#calendar').fullCalendar({ header: { left: 'prev,next today', center: 'title', right: 'month,basicWeek,basicDay, myCustomButton' }, customButtons: { myCustomButt
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay, myCustomButton'
},
customButtons: {
myCustomButton: {
text: 'Jump to date!',
click: function() {
// Jump to date function
alert('clicked the custom button!');
}
}
},
这将使日历在单击时转到特定日期:
customButtons: {
myCustomButton: {
text: 'Jump to date',
click: function() {
$("#calendar").fullCalendar('gotoDate', moment());
}
}
},
如图所示,这将简单地转到当前日期,实际上与内置的“今天”按钮的功能相同。如果您希望它做一些不同的事情,那么您可以潜在地做一些事情来允许用户选择一个日期。除了随意约会之外,这个问题还不清楚你到底想要什么,所以很难给出任何更具体的建议
有关fullCalendar gotoDate方法的详细信息,请参阅
请参阅上面代码的工作演示。是的,ADyson为您回答了这个问题,但只是为了澄清;该答案中给出的示例将带您到当前日期,例如,如果这是您的意图,您必须使用静态日期创建力矩对象-
date = moment("2018-01-04", "YYYY-MM-DD");
$("#calendar").fullCalendar( 'gotoDate', date );
或者,如果您需要使用日历的当前日期作为计算新日期的基础,例如向前一周,您可以执行以下操作-
currentDate = $('#calendar').fullCalendar('getDate');
newDate = moment(currentDate).add(7, 'days').format();
$("#calendar").fullCalendar( 'gotoDate', newDate );
有关操作矩.js对象的详细信息。欢迎使用堆栈溢出!请为你所问的问题提供更多的上下文,参见关于写一个好问题的文章。点击它。您的实际问题是什么?此外,您可以使用此代码将视图切换到相同的更改日期。$'日历'.fullCalendar'gotoDate',日期;$'日历“.fullCalendar”变更视图“,”代理日期“;