Adding rows and columns to a table dynamically with jQuery

后端 未结 3 1690
囚心锁ツ
囚心锁ツ 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:55

    I would avoid using strings of HTML and keep creating DOM elements like you had before. jQuery makes this really easy:

    var row = $("");
    row.append( $("").text("hello") );
    $("#tblSample").append(row);
    

    See http://api.jquery.com/jQuery/#jQuery2 for more info.

提交回复
热议问题