javascript 单击即可在 FullCalendar 中添加事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32644308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 15:33:37  来源:igfitidea点击:

Add events in FullCalendar on click

javascripthtmlcalendar

提问by Neeraj Verma

I am trying to add events on calendar cell click in .NET like this:

我正在尝试在 .NET 中的日历单元格中添加事件,如下所示:

http://arshaw.com/js/fullcalendar-1.5.3/demos/selectable.html

http://arshaw.com/js/fullcalendar-1.5.3/demos/selectable.html

I took the help of this post:

我接受了这篇文章的帮助:

create event with fullcalendar when clicking on calendar (rails)

单击日历(rails)时使用 fullcalendar 创建事件

I am getting the Selected date and text on Alert , bit not able to post it on selected cell ..

我收到了 Alert 上的 Selected date 和 text ,有点无法将其发布到选定的单元格上..

I have tried same solution on jsfiddle:

我在 jsfiddle 上尝试过相同的解决方案:

http://jsfiddle.net/5o66w860/

http://jsfiddle.net/5o66w860/

My code:

我的代码:

$(document).ready(function() {

    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();

    var events_array = [
        {
        title: 'Test1',
        start: new Date(2012, 8, 20),
        tip: 'Personal tip 1'},
    {
        title: 'Test2',
        start: new Date(2012, 8, 21),
        tip: 'Personal tip 2'}
    ];

    $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        selectable: true,
        events: events_array,
        eventRender: function(event, element) {
            element.attr('title', event.tip);
        },
        select: function(start, end, allDay) {
    var title = prompt('Event Title:');
    if (title) {
        calendar.fullCalendar('renderEvent',
            {
                title: title,
                start: start,
                end: end,
                allDay: allDay
            },
            true // make the event "stick"
        );
        /**
         * ajax call to store event in DB
         */
        jQuery.post(
            "event/new" // your url
            , { // re-use event's data
                title: title,
                start: start,
                end: end,
                allDay: allDay
            }
        );
    }
    calendar.fullCalendar('unselect');
}

    });
});

I also to remove , events array . .. but still not working

我也删除了,事件数组。..但仍然无法正常工作

回答by Neeraj Verma

Ok , got It after some googling :

好的,在谷歌搜索后得到了它:

Just need to change Code on select

只需要在选择时更改代码

select: function (start, end, jsEvent, view) {
                    var abc = prompt('Enter Title');
                    var allDay = !start.hasTime && !end.hasTime;
                    var newEvent = new Object();
                    newEvent.title = abc;
                    newEvent.start = moment(start).format();
                    newEvent.allDay = false;
                    $('#calendar').fullCalendar('renderEvent', newEvent);

                }

jsfiddle ;

jsfiddle ;

http://jsfiddle.net/5o66w860/

http://jsfiddle.net/5o66w860/