Get selected date from fullcalendar

后端 未结 2 1192
情歌与酒
情歌与酒 2021-02-06 14:54

I added the calendar to my asp.net mvc 2 application from here .

I want to pick the selected date where I am going to enter the event. How can I get selected date?

相关标签:
2条回答
  • 2021-02-06 15:13
    $('#calendar').fullCalendar({
        dayClick: function(date, jsEvent, view) {
    
            alert('Clicked on: ' + date.format());
    
            alert('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY);
    
            alert('Current view: ' + view.name);
    
            // change the day's background color just for fun
            $(this).css('background-color', 'red');
    
        }
    });
    
    0 讨论(0)
  • 2021-02-06 15:32

    Use this code when you setup the plugin

    $('#calendar').fullCalendar({
        selectable: true,
        select: function(start, end, jsEvent, view) {
             // start contains the date you have selected
             // end contains the end date. 
             // Caution: the end date is exclusive (new since v2).
             var allDay = !start.hasTime() && !end.hasTime();
             alert(["Event Start date: " + moment(start).format(),
                    "Event End date: " + moment(end).format(),
                    "AllDay: " + allDay].join("\n"));
        }
    });
    <link href="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.1.1/fullcalendar.min.css" rel="stylesheet"/>
    <link href="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.1.1/fullcalendar.print.css" rel="stylesheet" media="print"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.1.1/fullcalendar.min.js"></script>
    <div id="calendar"></div>

    Please note that I have just included the options needed to answer your question.

    For further information refer to the very good made plugin documentation.

    0 讨论(0)
提交回复
热议问题