fullCalendar - 未捕获的TypeError:无法调用undefined的方法'split'

时间:2013-03-23 11:32:24

标签: javascript jquery jquery-plugins fullcalendar

我在页面上填写所有月份,例如:

<?php foreach(range(0,11) as $month): ?>
      <div style='float:left; width:303px;' id='calenderSalesMonth_<?php echo $month ?>' class='calenderSales'></div>
<?php endforeach; ?>

fullCalendar应该通过id='calenderSalesMonth_*'设置特定月份,但这不会有效,我收到错误:

Uncaught TypeError: Cannot call method 'split' of undefined

代码:

$('.calenderSales').fullCalendar({
       editable: false,
       events:  { url: 'calender-events.php' },
       firstDay:1,
       month: $(this).attr("id").split("_")[1],
       year: 2013
});

1 个答案:

答案 0 :(得分:1)

用户month全局变量,然后设置它。

var month = $('.calenderSales').attr("id").split("_")[1];

$('.calenderSales').fullCalendar({
       editable: false,
       events:  { url: 'calender-events.php' },
       firstDay:1,
       month: month,
       year: 2013
});

使用.prop()替换.attr()

尝试将代码包装在$(window).load(function());