本文實例講述了JS實現從表格中動態刪除指定行的方法。分享給大家供大家參考。具體如下:
JS的表格對象有一個deleteRow方法用於刪除表格中的指定行,只需要指定行號即可
<!DOCTYPE html>
<html>
<head>
<script>
function deleteRow(r)
{
var i=r.parentNode.parentNode.rowIndex;
document.getElementById('myTable').deleteRow(i);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>Row 1</td>
<td><input type="button" value="Delete" onclick="deleteRow(this)"></td>
</tr>
<tr>
<td>Row 2</td>
<td><input type="button" value="Delete" onclick="deleteRow(this)"></td>
</tr>
<tr>
<td>Row 3</td>
<td><input type="button" value="Delete" onclick="deleteRow(this)"></td>
</tr>
</table>
</body>
</html>
希望本文所述對大家的javascript程序設計有所幫助。