Filtering: How to hide/show (toggle) certain table rows on click?

后端 未结 2 840
野性不改
野性不改 2021-01-29 12:07

Assuming this table (actually it could have more columns and rows):

Type Color&
2条回答
  •  后悔当初
    2021-01-29 12:48

    Here's a really really simple test that might help you get started.

        $(function () {
            $("#vehicles tr td").click(function () {
                var desc = $(this).html();
                $("#vehicles tr").css("background-color", "white");
                $("#vehicles").find(":contains(" + desc + ")").closest("tr").css("background-color", "red");
            });
        });
    

    This assigns a click event to every TD element, stores its value somewhere and then checks if said value exists in the table, highlighting the elements that are matched. Give it a spin, I think it'll set you off in the right direction.

提交回复
热议问题