Home  >  Article  >  Web Front-end  >  JS method to dynamically delete specified rows from a table_javascript skills

JS method to dynamically delete specified rows from a table_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:06:541461browse

The example in this article describes the JS method of dynamically deleting specified rows from a table. Share it with everyone for your reference. The details are as follows:

The JS table object has a deleteRow method for deleting specified rows in the table. You only need to specify the row number

<!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>

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn