Delete row
Copy codeThe Code is as follows:
<Script>
Function del (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 codeThe Code is as follows:
<Script>
Function uf_test (){
// Obtain the table object
Var tbTable = document. getElementById ("tb_test ");
// Insert a row
Var trT = tbTable. insertRow ();
// Get the number of td in the previous row
Var nRows = tbTable. rows [0]. cells. length;
// Insert td cyclically based on the number of td in the previous row
For (var I = 0; I <nRows; I ++ ){
// Create a td object
Var tdT = document. createElement ("TD ");
// Assign a value to the td object
// TdT. innerHTML = "sfsdf ";
TdT. innerText = "sfsdf ";
// Add td to tr
TrT. appendChild (tdT );
}
}
</Script>
<Table id = "tb_test" border = "1">
<Tr>
<Td> <input type = "text"> </td>
</Tr>
</Table>
<Input type = "button" onclick = "uf_test ();" value = "add a row">