我正在使用Fullcalendar选择假期,目前在选择之前工作正常。
我可以选择多个日期,但是当我更改月份并返回时,Fullcalendar不记得选择的日期了。
我希望能够选择所有日期,然后按下“提交”按钮,这样我可以一键保存所有日期。
我的JavaScript代码是:
var events= [{
id : 0,
title: 'All Day Event',
start: new Date(2016, 3, 5)
}];
var i=1;
$(document).ready(function() {
$('#calendar').fullCalendar({
events: events,
dayClick: function(date, jsEvent, view) {
// change the day's background and save the day selected
$(this).css('background-color', 'green');
var temp={id: i, title: 'Holidays', start: new Date(date)};
i=i+1;
events.push(temp);
$('#calendar').fullCalendar( 'renderEvent', temp );
}
});
});
有什么建议吗?
谢谢。
最佳答案
您需要添加一个标志以使事件永久生效,如下所示:
$('#calendar').fullCalendar({
events: events,
dayClick: function(date, jsEvent, view) {
var temp={id: i, title: 'Holidays', start: new Date(date)};
i=i+1;
events.push(temp);
$('#calendar').fullCalendar( 'renderEvent', temp, true );
}
});
您还可以在事件中添加“ backgroundColor”以标识您的选择,因为设置表单元格的背景色会在您前后移动时丢失。
var temp={id: i, title: 'Holidays', start: new Date(date), backgroundColor: 'green'};