2011-03-10 140 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') - 這樣你就不需要編輯插件。
現在,在關閉對話框並重新打開後,只會出現一個日曆。

相關問題