jQuery 从全日历中获取所选日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3959258/
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-08-26 16:25:21  来源:igfitidea点击:

Get selected date from fullcalendar

jqueryfullcalendar

提问by Red Swan

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

我从这里将日历添加到我的 asp.net mvc 2 应用程序中。

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

我想选择我要参加活动的所选日期。我怎样才能得到选定的日期?

Also I want to save this date and corresponding event to the database. How to do this also ?

另外我想将此日期和相应的事件保存到数据库中。这也怎么办?

回答by Lorenzo

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.

有关更多信息,请参阅非常好的插件文档

回答by Ram K

$('#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');

    }
});