Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 16:06:54
Original
1486 people have browsed it

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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template