Adding rows and columns to a table dynamically with jQuery

后端 未结 3 1658
囚心锁ツ
囚心锁ツ 2021-01-12 08:55

I have the following JavaScript code:

function addRowToTable()
{
  var tbl = document.getElementById(\'tblSample\');
  var lastRow = tbl.rows.length;
  // if         


        
3条回答
  •  醉梦人生
    2021-01-12 09:43

    Maybe something like this (but without select): http://jsfiddle.net/dVBMc/3/

    UPDATE: http://jsfiddle.net/dVBMc/6/

    function addRowToTable(table, cell1, cell2) {
        var row;
        row = "" + cell1 + "" + cell2 + "";
        table.append(row);
    }
    

    Usage:

    $(document).ready(function() {
        $('button').click(function() {
            addRowToTable($('table'), 'cell1 content', 'cell2 content');
        });
    });
    

提交回复
热议问题