【问题标题】:fullCalendar - Uncaught TypeError: Cannot call method 'split' of undefinedfullCalendar - 未捕获的类型错误:无法调用未定义的方法“拆分”
【发布时间】:2013-03-13 05:59:24
【问题描述】:

我正在填充页面上的所有月份,例如:

<?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
});

【问题讨论】:

  • 如果.attr("id")返回undefined,则不能调用.split,因为.split是String对象的方法,不能在undefined上调用。
  • 这段代码是否在某个click 事件处理程序中?
  • @dfsq 不是。
  • @I'll-Be-Back 尝试使用.prop()
  • @DipeshParmar .attr("id") return Unexpected identifier - 不确定现在的解决方案是什么...?

标签: javascript jquery jquery-plugins fullcalendar


【解决方案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());

【讨论】:

  • 声明一个全局的month 变量是行不通的,因为我在一个页面上有很多个月,例如:calenderSales_0calenderSales_1calenderSales_2
  • 升级的 jQuery,prop 不能工作。同样的错误..month: $(this).prop("id").split("_")[1],
  • @I'll-Be-Back 嘿,兄弟正在解决您的问题..不要通过对我投反对票来发脾气...
猜你喜欢
  • 2011-12-20
  • 2013-08-31
  • 2011-11-12
  • 2013-09-14
  • 2013-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多