每当我尝试更改标题时,它第一次都可以正常工作,但是如果我尝试在不刷新的情况下更改另一个事件的标题,则以前更改的事件标题和当前事件标题都会更改。
您可以在下面找到完整日历的自定义JavaScript文件。但是当我更改事件的标题并手动刷新时,它工作正常。
function init_calendar() {
if( typeof ($.fn.fullCalendar) === 'undefined'){ return; }
var date = new Date(),
d = date.getDate(),
m = date.getMonth(),
y = date.getFullYear(),
started,
categoryClass;
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay,listMonth'
},
selectable: true,
selectHelper: true,
eventLimit: true,
select: function(start, end, allDay)
{
$('#fc_create').click();
started = moment(start).format('YYYY/MM/DD, h:mm:ss A');
ended = moment(end).format('YYYY/MM/DD, h:mm:ss A');
$(".antosubmit").on("click", function() {
var title = $("#title").val();
categoryClass = $("#event_type").val();
if (title) {
var start = moment(start).format('YYYY/MM/DD HH:mm:ss');
var end = moment(end).format('YYYY/MM/DD HH:mm:ss')
$.ajax({
url:"add.php",
type:"POST",
data:{title:title, start:started, end:ended},
success:function()
{
calendar.fullCalendar('refetchEvents');
alert("Added Successfully");
}
})
}
$('#title').val('');
calendar.fullCalendar('unselect');
$('.antoclose').click();
return false;
});
},
editable:true,
eventDrop:function(event)
{
var start = moment(event.start).format('YYYY/MM/DD HH:mm:ss');
var end = moment(event.end).format('YYYY/MM/DD HH:mm:ss');
var title = event.title;
var id = event.id;
$.ajax({
url:"event_change.php",
type:"POST",
data:{title:title, start:start, end:end, id:id},
success:function()
{
calendar.fullCalendar('refetchEvents');
alert("Event Updated");
}
});
},
editable:true,
eventResize:function(event)
{
var start = moment(event.start).format('YYYY/MM/DD HH:mm:ss');
var end = moment(event.end).format('YYYY/MM/DD HH:mm:ss');
var title = event.title;
var id = event.id;
$.ajax({
url:"event_change.php",
type:"POST",
data:{title:title, start:start, end:end, id:id},
success:function(){
calendar.fullCalendar('refetchEvents');
alert('Event changed');
}
})
},
eventClick: function(calEvent, jsEvent, view) {
$('#fc_edit').click();
var id = calEvent.id;
categoryClass = $("#event_type").val();
$(".antoremove2").on("click", function(){
categoryClass = $("#event_type").val();
$.ajax({
url:"remove.php",
type:"POST",
data:{id:id},
success:function()
{
calendar.fullCalendar('refetchEvents');
alert("Event Removed");
}
})
});
$(".antosubmit2").on("click", function() {
calEvent.title = $("#title2").val();
var id = calEvent.id;
var title = calEvent.title;
var start = moment(calEvent.start).format('YYYY/MM/DD HH:mm:ss');
var end = moment(calEvent.end).format('YYYY/MM/DD HH:mm:ss');
console.log(title);
console.log(id);
console.log(start);
console.log(end);
$.ajax({
url:"event_change.php",
type:"POST",
data:{title:title,start:start, end:end, id:id},
success:function(){
calendar.fullCalendar('refetchEvents');
alert('Event changed');
}
});
calendar.fullCalendar('updateEvent', calEvent);
$('.antoclose2').click();
});
calendar.fullCalendar('unselect');
},
editable: true,
events:'view.php',
});
};
$(document).ready(function() {
init_calendar();
});
您可以使用.one('event')
方法代替.on('event')
。然后,您可以逐个管理事件,而无需更改之前选择的事件。