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

后端 未结 12 531
南方客
南方客 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:45

    As said in the other answers, doing it on a large table on the client side will be slower than on the server side, and may not work if the user has javascript disabled.

    However, using a JS framework like jQuery makes it so easy that it's really tempting :

    $(document).ready(function() {
      $('.myTable tr:odd').addClass('alternateRow');
    });
    

提交回复
热议问题