JavaScript添加类不起作用?

时间:2013-03-05 15:40:15

标签: javascript jquery

我有以下JS功能:

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

我真的不确定为什么第一个工作而不是这个......

由于

2 个答案:

答案 0 :(得分:2)

更改您的选择器,而不是:

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

尝试:

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

答案 1 :(得分: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之间的空格

第一个是在th中使用类.fc-resourceName查找另一个元素,而实际上您需要该元素。