使用 Jquery 将事件动态插入到 Fullcalendar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11063568/
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
Insert event dynamically to Fullcalendar using Jquery
提问by Ori Refael
I am having trouble to add new event to fullCalendar using Jquery. I am using Eclipse to develop web and not familiar with Ajax at all and aperantly, it does not work with my eclipse.
我无法使用 Jquery 向 fullCalendar 添加新事件。我正在使用 Eclipse 开发 Web 并且根本不熟悉 Ajax,而且它不适用于我的 Eclipse。
Everything is written inside a button.click function in jquery.
一切都写在 jquery 的 button.click 函数中。
var subject = $("#txtEventName").val(); //the title of the event
var dateStart = $("#txtDate").val(); //the day the event takes place
var dateEnd = $("#txtDateEnd").val(); //the day the event finishes
var allDay = $("#alldayCheckbox").val(); //true: event all day, False:event from time to time
var events=new Array();
event = new Object();
event.title = subject;
event.start = dateStart; // its a date string
event.end = dateEnd; // its a date string.
event.color = "blue";
event.allDay = false;
events.push(event);
$('#calendar').fullCalendar('addEventSource',events);
No bugs were detected but the event is not created. P.S: I would like to stay with array feed if no other way in jQuery.
未检测到错误,但未创建事件。PS:如果在 jQuery 中没有其他方式,我想继续使用数组提要。
回答by Adil Malik
Try this:
尝试这个:
var newEvent = new Object();
newEvent.title = "some text";
newEvent.start = new Date();
newEvent.allDay = false;
$('#calendar').fullCalendar( 'renderEvent', newEvent );
Note that when you assign value to startit needs to be in one of the supported formats.
请注意,当您分配值以启动时,它需要采用一种受支持的格式。
You may specify a string in IETF format (ex: Wed, 18 Oct 2009 13:00:00 EST
), a string in ISO8601 format (ex: 2009-11-05T13:15:30Z
) or a UNIX timestamp.
您可以指定 IETF 格式Wed, 18 Oct 2009 13:00:00 EST
的字符串(例如:)、ISO8601 格式的字符串(例如:)2009-11-05T13:15:30Z
或 UNIX 时间戳。