如何通过单击按钮在全日历中添加任何事件?

问题描述 投票:0回答:1

我在每天/单元格上添加了(“+”)按钮。

var add_button = '<input type="button" value="+" />'; 
$(".fc-day-number").prepend(add_button);

calendar with each cells having button to add event

如何在单击此(“+”)按钮后添加事件,可以通过编写以下内容在任何一天的单击时执行相同的操作:

dayClick: function(date) {
                addEvent(date);                 
            },

function addEvent(date) {
    var newEvent = {
    title: timeSlot,
    start: date.format()
    };
}
javascript jquery jsp fullcalendar
1个回答
0
投票

单击按钮后,您可以打开一个对话框。对话是一种吸收价值观的形式。保存表单后,您可以执行 jquery ajax 调用将其保存到存储中。

dayClick: function (date, allDay, jsEvent, view) {
            $('#eventTitle').val("");
            $('#eventDate').val($.fullCalendar.formatDate(date, 'dd/MM/yyyy'));
            $('#eventTime').val($.fullCalendar.formatDate(date, 'HH:mm'));
            ShowEventPopup(date);
        },

function ShowEventPopup(date) {

    $('#popupEventForm').modal('show');
    $('#eventTitle').focus();
}

$('#btnPopupSave').click(function () {

    $('#popupEventForm').hide();

    var dataRow = {
        'Title': $('#eventTitle').val(),
        'NewEventDate': $('#eventDate').val(),
        'NewEventTime': $('#eventTime').val(),
        'NewEventDuration': $('#eventDuration').val()
    }

    ClearPopupFormValues();

    $.ajax({
        type: 'POST',
        url: "/Diary/SaveEvent",
        data: dataRow,
        success: function (response) {
            if (response == 'True') {
                $('#calendar').fullCalendar('refetchEvents');
                alert('New event saved!');
            }
            else {
                alert('Error, could not save event!');
            }
        }
    });
});
© www.soinside.com 2019 - 2024. All rights reserved.