HTML DOM Table deleteRow () method
Definition and Usage
deleteRow () method is used to delete the specified location from the table row
grammar
tableObject.deleteRow(index)
值 | 描述 |
---|---|
index | 指定删除指定行的数字索引 (以 0 开始). |
Browser Support
All major browsers support deleteRow () method
Examples
Examples
Delete the first line of the table:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
document.getElementById("myTable").deleteRow(0);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
<tr>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">删除表格第一行</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
document.getElementById("myTable").deleteRow(0);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
<tr>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">删除表格第一行</button>
</body>
</html>
try it"
More examples
Click to delete the table row
In this example, click after use deleteRow () method to delete rows
Table Object