2013-03-23 72 views
1

我填充所有月份页面上的“分裂”,例如: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 
}); 
+0

如果'.attr( “ID”)'收益不确定的,你不能叫'.split'就可以了,因为'.split'是一个String对象的方法,不能在未定义时调用。 – 2013-03-23 11:36:40

+0

这个代码在一些'click'事件处理程序中吗? – dfsq 2013-03-23 11:36:58

+0

@dfsq不,它不是。 – 2013-03-23 11:39:23

回答

1

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

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

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

OR

使用.prop().attr()替代。

OR

尝试包里面的代码$(window).load(function());

+0

声明一个全局'月份'变量不会工作,因为我在页面上有很多个月,例如:'calenderSales_0','calenderSales_1','calenderSales_2' – 2013-03-23 11:50:41

+0

@ I'll-Be-Back ohh所以你试过了'prop()' – 2013-03-23 11:53:28

+0

升级jQuery,'prop'不会工作。同样的错误。'month:$(this).prop(“id”)。split(“_”)[1],' – 2013-03-23 12:02:35

相关问题