Dynamically hiding table rows with jQuery

后端 未结 3 630
有刺的猬
有刺的猬 2021-01-19 11:19

I am trying to alternate background colors of table rows, each section starting with the same color. I have achieved this with the following code:

$(document         


        
3条回答
  •  悲&欢浪女
    2021-01-19 11:25

    This should do the trick:

    $(function() {
        $('#showAll').click(function() {
            $('table > tbody').each(function() {
                $(this).children('tr:gt(4)').toggle();
            });
            $("tr:visible").filter(':odd').css("background", "#efefef").end()
                .filter(':even').css("background", "#ffffff");
        }).click();
    });
    

    Edited to clean up code (inspired by @karim79's answer).

提交回复
热议问题