如何限制Fullcalendar在过去几天禁用所有类型的操作?

时间:2013-12-18 06:17:25

标签: javascript fullcalendar

我想在过去几天禁用所有类型的操作。

这是我尝试过的:

http://jsfiddle.net/7MTdn/275/

我也在这里提供我的代码:

$('#mycalendar').fullCalendar(
            {
             header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,agendaWeek,agendaDay'
                    },


                dayClick: function( date, allDay, jsEvent, view ) { 

                                    var getFromDate = date.getFullYear()+'-'+parseInt(date.getMonth()+1)+'-'+date.getDate();

                var newDate = new Date();
                var newD    = newDate.getDate();
                var newM    = newDate.getMonth();
                var newY    = newDate.getFullYear();

                var myDate  = newY+'-'+newM+'-'+newD;

                alert(Number(myDate));

                alert(Number(getFromDate));

                if(getFromDate<myDate)
                {
                    alert("Sorry! You cannot add event on past dates.");
                    return false;
                }
                else
                {
                    alert("You can add an event on this date");
                }


            },      

             events: [

                        {
                            title  : 'eventTest',
                            start  : '2013-12-18',
                            end    : '2013-12-26'
                        }
                    ]
           }); 

1 个答案:

答案 0 :(得分:2)

我认为cond需要像这样的东西......

     var getFromYr = date.getFullYear();
                var getFromMonth= date.getMonth()+1;
                 var getFromDay =  date.getDate();

            var newDate = new Date();
                var newD = newDate.getDate(); 
                var newM = newDate.getMonth()+1;
                var newY = newDate.getFullYear();
         if(getFromYr<newY || (getFromYr==newY && getFromMonth<newM) ||(getFromMonth==newM && getFromDay <newD)  )     
            {
                alert("Sorry! You cannot add event on past dates.");
                return false;
            }

Fiddle Demo