2011-03-10 111 views
3

我正在使用Fullcalendar for jQuery,由于某种原因,日历在页面上出现两次。这不是关于在同一页面上有两个fullcalendar实例的问题。Fullcalendar:为什么日历在页面上出现两次?

相反,在第一个日历的底部,有第二个相同的日历。

我确认在我的页面中只有一个#calendar div,所以这个错误与我的.js有关,我调用fullcalendar.js,我相信。

任何帮助非常感谢。

JS代码:

jQuery('#calendar').fullCalendar({ 


     year: jQuery.today.getFullYear(), 
     month: jQuery.today.getMonth(), 
     date: jQuery.today.getDate(), 
     theme: true, 
     contentHeight: 1000, 
     header: { 
      left: 'prev,next today', 
      center: 'title', 
      right: 'month,agendaWeek,agendaDay' 
     }, 
     defaultView: 'agendaDay', 
     dayClick: function(date, allDay, jsEvent, view) { 
          // a lot of custom code 
        } 
      }); 

HTML:

<table><tr><td valign="top" width="700px"><div id="calendar"></div></td></tr></table> 

其他fullcalendar的javascript调用(这会一个datepicker在DIV到左同一页上#calendar的div):

jQuery('#datepicker_for_calendar').datepicker({ 
      defaultDate: jQuery.today, 
      minDate: jQuery.startDate, 
      maxDate: jQuery.endDate, 
      inline: true, 
      showButtonPanel: true, 
      onSelect: function(dateText, inst) { 
       var d = new Date(dateText); 
       jQuery('#calendar').fullCalendar('gotoDate', d); 
       selectedDate = d; 
      } 
     }); 
+3

请问您可以发布相关的HTML和JavaScript? – Brandon 2011-03-10 19:20:17

+0

我在fullcalendar调用中有相当多的代码,希望会有一个通用的原因。将尽力减少问题的代码。 – netefficacy 2011-03-10 19:26:18

+0

“相当多的代码”很可能是问题的一部分。另外,你还有其他'fullCalendar'调用(使用字符串参数进行操作)? – justkt 2011-03-10 19:38:56

回答

1

好吧,经过长达一周的错误测试,我发现这个jQuery插件:

一次()

http://plugins.jquery.com/project/once

一旦.fullcalendar之前施加到#calendar DIV,问题解决,只呈现一个日历。

工作代码:

jQuery('#calendar').once('calendar').fullCalendar({ 

... })

2

我最近遇到了同样的问题,尝试了一次()的jQuery插件,它并没有为我工作。但是,我重新下载了非缩小的源代码,并在initialRender方法中添加了以下行作为方法的第一行,并解决了我的重复日历方法。

element.html('');

我的猜测是我的问题是一个事实,即我被重新初始化一个下拉更改日历而无需刷新页面,这似乎是JS代码不断追加日历现有的div来没有清除现有的日历。

3

a.html('');添加到缩小版本中的功能f()
我有我的对话框打开,每次我点击一个按钮打开那里会有另一个日历。
经过一番阅读,我发现使用方法 - .fullCalendar('destroy') - 这样你就不需要编辑插件。
现在,在关闭对话框并重新打开后,只会出现一个日历。

相关问题