首页 > 技术文章 > jq遍历table 下的 td 添加类

enych 2018-01-31 16:46 原文

    <script>
        $('#btntb').click(function () {
            $('#tab tr').each(function (i) { // 遍历 tr
                $(this).children('td').eq(1).addClass('content');
                //$(this).children('td').each(function (j) {  // 遍历 tr 的各个 td
                //  //  console.log($(this).text());
            
                //});
            });
        });

        //$(function () {
        //    $("#btn").click(function () {
        //        $("#test tr td:nth-child(2)").addClass('red');
        //    });
        //    $("#test tr").click(function () {
        //        $(this).children('td').eq(1).addClass('red');
        //    });
        //});
        window.onload = function () {
        
        }
    </script>

 

$(this).children('td').eq(1).css({ "text-align" :"left" });

 

推荐阅读