What is the best way to style alternating rows in a table?

后端 未结 12 506
南方客
南方客 2020-12-11 11:09

Obviously, the actual style of the odd/even rows will be done via a CSS class, but what is the best way to \"attach\" the class to the rows? Is is better to put it in the ma

12条回答
  •  囚心锁ツ
    2020-12-11 11:37

    You can do this fairly easily with jQuery, like so:

    $(function(){
        $('tr:even').addClass('alternateClass');
        $('tr:odd').addClass('mainClass');
    });
    

    You can qualify the selector a bit more if you just want to do this on one particular table, or do it on 'li' elements as well.

    I think this is a bit cleaner and more readable client-side than it would be in some server-side environments,

提交回复
热议问题