2012-06-16 128 views
5

我無法使用Jquery將新事件添加到fullCalendar。我使用Eclipse開發Web,並且完全不熟悉Ajax,它不適用於我的eclipse。使用Jquery動態插入事件到Fullcalendar

所有內容都寫在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); 

未檢測到錯誤但未創建事件。 P.S:如果沒有其他方式在jQuery中,我想留在數組中。

+0

「事件」是Javascript中的保留字,所以在代碼中更改「事件」對象名稱,它可能工作。 –

+0

@Furqan我做到了,還沒有工作:( –

+0

哪些.js文件包含在您的HTML中? – ganeshk

回答

11

試試這個:

var newEvent = new Object(); 

newEvent.title = "some text"; 
newEvent.start = new Date(); 
newEvent.allDay = false; 
$('#calendar').fullCalendar('renderEvent', newEvent); 

注意,當您將值分配給start它需要在所支持的格式之一。

您可以指定IETF格式的字符串(例如:「Wed,18 Oct 2009 13:00:00 EST」),ISO8601格式的字符串(例如:「2009-11-05T13:15:30Z」)或UNIX時間戳。

相關問題