在表格中每隔一行着色时遇到问题

时间:2011-10-24 16:06:53

标签: jquery

在应用某些过滤器并且某些行变为隐藏/可见之后,我无法对表格的每一行进行着色。立即调用$("#tableJudges tr:not([th]):even").addClass("altr");,只要隐藏/显示行,就会调用$('#tableJudges').removeClass('altr').filter(':visible:not([th]):even').addClass('altr');。仍然有多行被着色,而不是每隔一行被着色。谁能告诉我为什么会这样?

完整来源:

$(document).ready(function(){
        $("#tableJudges tr:not([th]):even").addClass("altr");
            toggleJudges();

    // inactive/active judge drop down changed
    $('#judgeStatusDropDown').change(function(){
        toggleJudges();
    });

    // judge section drop down changed
    $('#judgeSectionDropDown').change(function(){
        toggleJudges();
    });
});

function toggleJudges(){

    var selectedString = $('#judgeStatusDropDown').val() + ' ' + $('#judgeSectionDropDown').val();
    switch (selectedString){
        case 'Both All Sections':
            $('#tableJudges tr').show();
            $('#tableJudges').removeClass('altr').filter(':visible:not([th]):even').addClass('altr');
            break;

        case 'Both Bowens':
            $('#tableJudges tr:gt(1)').hide();
            $('#tableJudges tr[info="Active Bowens"]').show();
            $('#tableJudges tr[info="Inactive Bowens"]').show();
            $('#tableJudges').removeClass('altr').filter(':visible:not([th]):even').addClass('altr');
            break;

        case 'Both Complex':
            $('#tableJudges tr:gt(1)').hide();
            $('#tableJudges tr[info="Active Complex"]').show();
            $('#tableJudges tr[info="Inactive Complex"]').show();
            $('#tableJudges').removeClass('altr').filter(':visible:not([th]):even').addClass('altr');
            break;

        case 'Both Non-complex':
            $('#tableJudges tr:gt(1)').hide();
            $('#tableJudges tr[info="Active Non-Complex"]').show();
            $('#tableJudges tr[info="Active Non-Complex"]').show();
            $('#tableJudges').removeClass('altr').filter(':visible:not([th]):even').addClass('altr');
            break;

        case 'Both Specialty':
            $('#tableJudges tr:gt(1)').hide();
            $('#tableJudges tr[info="Active Specialty"]').show();
            $('#tableJudges tr[info="Active Specialty"]').show();
            $('#tableJudges').removeClass('altr').filter(':visible:not([th]):even').addClass('altr');
            break;

        case 'Inactive All Sections':
            $('#tableJudges tr:gt(1)').hide();
            $('#tableJudges tr[info="Inactive Bowens"]').show();
            $('#tableJudges tr[info="Inactive Complex"]').show();
            $('#tableJudges tr[info="Inactive Non-complex"]').show();
            $('#tableJudges tr[info="Inactive Specialty"]').show();
            $('#tableJudges').removeClass('altr').filter(':visible:not([th]):even').addClass('altr');
            break; 

        case 'Active All Sections':
            $('#tableJudges tr:gt(1)').hide();
            $('#tableJudges tr[info="Active Bowens"]').show();
            $('#tableJudges tr[info="Active Complex"]').show();
            $('#tableJudges tr[info="Active Non-complex"]').show();
            $('#tableJudges tr[info="Active Specialty"]').show();
            $('#tableJudges').removeClass('altr').filter(':visible:not([th]):even').addClass('altr');
            break;          

        default:
            $('#tableJudges tr:gt(1)').hide();
            $('#tableJudges tr[info="'+selectedString+'"]').show();
            $('#tableJudges').removeClass('altr').filter(':visible:not([th]):even').addClass('altr');
    }
}

1 个答案:

答案 0 :(得分:2)

$('#tableJudges').removeClass('altr')应为$('#tableJudges tr').removeClass('altr')