alternate row colors using jquery

后端 未结 6 1342
被撕碎了的回忆
被撕碎了的回忆 2021-02-05 18:38

Using jQuery and not CSS, is it possible to alternate row colors between records? If so can anyone provide a short code script on how to accomplish this?

6条回答
  •  故里飘歌
    2021-02-05 19:14

    For anyone wanting to skip over hidden rows (or another attribute, say class="struck"):

    
    function doZebra(){
         var tTrCnt=0;
         $("##tblData tbody tr").each(function(){
             if($(this).css("display")!="none" && !$(this).hasClass("struck")){
                 tTrCnt++;
                 if(tTrCnt % 2) $(this).removeClass().addClass("eee");
                 else  $(this).removeClass().addClass("fff");
             }
         });
    }
    

提交回复
热议问题