最近需要用到一个美观的日历作为前台呈现,找了好久决定用fullcalendar-1.5.4进行展示。
fullcalendar-1.5.4本身自带的api太过冗杂,我只取了部分需要用到的功能。同时感谢下这几个网址:
http://arshaw.com/fullcalendar/docs/(官方API)
http://www.cnblogs.com/mycoding/archive/2011/05/20/2052152.html(某大神翻译的API)
我要做的目的是将每一天的那个容器里面放入事件,随后点击每个事件触发不同的效果。于是我先定义了一些事件数组
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
theme: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
events: [
{
id: 1,
title: '3条信息',
start: new Date(y, m, 1),
backgroundColor:'red',
editable:false
},
{
id: 2,
title: '2张照片',
start: new Date(y, m, 1),
backgroundColor:'yellow',
editable:false
},
{
id: 3,
title: '3条分享',
start: new Date(y, m, 1),
backgroundColor:'blue',
editable:false
},
分别将它们用不同颜色区别,同时赋予ID属性。
接着写出来点击每个event会触发的事件
//点击事件
eventClick: function(calEvent, jsEvent, view){
// alert(calEvent.id);
//如果点击事件的ID为1表示是信息,2是照片,3是其他
if(calEvent.id==1){
alert('今天是'+calEvent.start+'今天有'+calEvent.title);
}else if(calEvent.id==2){
alert('今天是'+calEvent.start+'今天有'+calEvent.title);
$("#slider").show();
}else if(calEvent.id==3){
alert('今天是'+calEvent.start+'今天有'+calEvent.title);
}
}
});
例如我要在点击照片后显示一叠照片,我就可以在id==1的判断里面写上内容,总之今天只看了这么多,明天研究接下来怎么写