2013-03-05 174 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,而你實際上想要那個元素。