Create clone of table row and append to table in JavaScript

前端 未结 3 1181
小蘑菇
小蘑菇 2020-12-01 05:32

In JavaScript, how can I add a row dynamically to a table? On a JavaScript event I want to create a similar row and append to the table.

3条回答
  •  一生所求
    2020-12-01 05:51

    tried all sorts of searches today, made use of sources : http://www.mredkj.com/tutorials/tablebasics3.html and http://www.mredkj.com/tutorials/tableaddcolumn.html

    here's the result of my logic research, it's working now

        function addRow(id)
        { var x=document.getElementById(id).tBodies[0];  //get the table
          var node=t.rows[0].cloneNode(true);    //clone the previous node or row
          x.appendChild(node);   //add the node or row to the table
        }  
    
        function delRow(id)
        { var x=document.getElementById(id).tBodies[0]; //get the table
          x.deleteRow(1); //delete the last row
        }
    

    NOTE1: my table contained a cell that had a textbox + a label in it per table row(tr).
    NOTE2: in a row, there were multiple (td)'s that had a label + textbox

提交回复
热议问题