jquery <table>中选中一行,行背景色改变

css文件中

.lineColor
{
    background-color: #eeeeee;
}

js文件中


function TableRowSelectColor(clsName) {

    $(clsName).find("tr").click(function () {

        var rows = $(this).parent().find("tr");

        if(rows.hasClass("lineColor"))
        {
            rows.removeClass("lineColor");
        }

        $(this).addClass("lineColor");
    });

}

php文件中

    <script src="../lib/jquery-3.5.1.js"></script>
    <script src="../js/tableDeal.js"></script>
    <script>
        $(function () {
            TableRowSelectColor(".tb_1");
        });
    </script>

    

    <table class="tb_1">
    <tr>
    </tr>
    </table>

猜你喜欢

转载自blog.csdn.net/modern358/article/details/115212218