我在单击" x&quot" x&quot"时尝试删除事件,但不起作用,并且不遇到任何错误。
我分配函数单击参数中的" EventRender"。
这是我的JavaScript的代码:
$('#calendar').fullCalendar({
locale: 'es',
weekends: false, //ocultar fines de semana
defaultView: 'agendaWeek',
allDaySlot: false,
header: {
left: 'month,agendaWeek,agendaDay,listDay',
center: 'title',
right: 'prev,next today'
},
height: 'auto',
minTime: "10:00:00",
maxTime: "20:00:00",
editable: true,
//droppable: true, // this allows things to be dropped onto the calendar
dayClick: function(date, jsEvent, view) {
console.log('Clicked on: ' + date.format());
console.log('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY);
console.log('Current view: ' + view.name);
var hoy = moment();
if(date.format("YYYY-MM-DD HH:mm") >= hoy.format("YYYY-MM-DD HH:mm")){
asignarCita(date);
}else{
swal({
title: "Cita no disponible",
text: "La fecha u hora seleccionada ya ha pasado."
});
}
},
eventRender: function(event, element) {
element.prepend( "<div class='ibox-tools'><a style='background-color: transparent; margin-right: 10px' class='pull-left'><i class='fa fa-times closeon'></i></a></div>" );
//element.append( "<span class='closeon'>X</span>" );
console.log(element.find('closeon'));
element.find(".closeon").click(function() {
$('#calendar').fullCalendar('removeEvents',event._id);
});
},
events: [
{
title: 'All Day Event',
start: '2014-10-01'
},
{
title: 'Long Event',
start: '2014-10-07',
end: '2014-10-10'
},
{
id: 999,
title: 'Repeating Event',
start: '2014-10-09T16:00:00'
},
],
});
问题在哪里?
尝试以下:
eventRender: function(event, element, view) {
if (view.name == 'listDay') {
element.find(".fc-list-item-time").append("<span class='closeon'>X</span>");
} else {
element.find(".fc-content").prepend("<span class='closeon'>X</span>");
}
element.find(".closeon").on('click', function() {
$('#calendar').fullCalendar('removeEvents',event._id);
console.log('delete');
});
},
https://jsfiddle.net/vc9ytv2k/
当前版本的FullCalendar具有不同的API
eventRender: function(info) {
$(info.el).append("<span class='removebtn'>X</span>");
$(info.el).find(".removebtn").click(function() {
info.event.remove();
});
}