2013-03-05 106 views
0

我有以下JS功能:JavaScript添加类不工作?

function addTopLinks() { 

    $('#calendar .fc-view-resourceNextWeeks thead th .fc-resourceName') 
.addClass('top-cell'); 
}; 

它不添加类。

我还有一个:

function addDayClass() { 
    $('#calendar .fc-view-resourceNextWeeks thead th') 
     .filter(function() { 
      if ($(this).text().indexOf('Mon ') == 0) return true; 

      return false; 
     }) 
     .addClass('monday'); 
}; 

那一个工作就好了。

这是层级:

enter image description here

我真的不知道为什么第一个是工作,没有这一条......

感谢

+0

你能告诉我们你在哪里调用addTopLinks吗? – 2013-03-05 15:42:05

+0

你为什么如此特定目标fc-resourceName? – 2013-03-05 15:42:27

+0

难道你不能只使用[.find()](http://api.jquery.com/find/)? – 2013-03-05 15:42:41

回答

2

改变你的选择,而不是作者:

'#calendar .fc-view-resourceNextWeeks thead th .fc-resourceName'

尝试:

'#calendar .fc-view-resourceNextWeeks thead th.fc-resourceName'

1
$('#calendar .fc-view-resourceNextWeeks thead th .fc-resourceName').addClass('top-cell'); 

应该

$('#calendar .fc-view-resourceNextWeeks thead th.fc-resourceName').addClass('top-cell'); 

(注th.fc-resourceName之间去除空间)

第一个是找另一个元素在之内与类.fc-resourceName,而你实际上想要那个元素。