Delete row
Copy the code code as follows:
<script>
functiondel(obj)
{
obj.parentNode.parentNode.removeNode(true);
}
</script>
<body>
<table>
<tr>
<td>Cell 1</td>
<td><input type=button value="delete this row" onclick="del(this)"></td>
</tr>
<tr>
<td>Cell 2</td>
<td><input type=button value="delete this row" onclick="del(this)"></td>
</tr>
<tr>
<td>Cell 3</td>
<td><input type=button value="delete this row" onclick="del(this)"></td>
</tr>
</table>
</body>
Add row
Copy the code code as follows:
<script>
function uf_test(){
//Get table object
var tbTable = document.getElementById("tb_test");
//Insert a row
var trT = tbTable.insertRow();
//Get the td number of the previous row
var nRows = tbTable.rows[0].cells.length;
//According to the td number of the previous row, insert td in a loop
for(var i = 0; i < nRows; i++){
//Create td object
var tdT = document.createElement("TD");
//Assign value to td object
//tdT.innerHTML="sfsdf";
tdT.innerText="sfsdf";
//Add td to tr
trT.appendChild(tdT);
}
}
</script>
<table id="tb_test">
<tr>
<td><input type="text"></td>
</tr>
</table>
<input type="button" onclick="uf_test();" value="Add a row">