How to set table cell value using jquery

后端 未结 5 874
情书的邮戳
情书的邮戳 2021-02-09 18:30

I would like to set the value of all the cells of a table by iterating through them. Ideally I would like to access a Html table like an array i.e. $(\"#tbl\")[row][col]=\

5条回答
  •  后悔当初
    2021-02-09 18:57

    If you simply want to assign a value to all the cells try this:

    $(document).ready(function () {
        $("#tbl td").append("sdfasdf");
    });
    

    If you want to extract the cells as 2 dimensional array:

    $(document).ready(function () {
        var rowsNcells = $.map($("#tbl tr"),
        function(el, ind){
            var row = [];
            $("td", el).each(function(){
                row.push(el);
            });
            return row;
        });
    });
    

    and then somewhere in the code.

    $(rowNcells[1][2]).text("Something");
    

提交回复
热议问题