源代码 :
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>开源教程(ossoft.cn)</title> <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>行 1</td> <td><input type="button" value="删除" onclick="deleteRow(this)"></td> </tr> <tr> <td>行 2</td> <td><input type="button" value="删除" onclick="deleteRow(this)"></td> </tr> <tr> <td>行 3</td> <td><input type="button" value="删除" onclick="deleteRow(this)"></td> </tr> </table> </body> </html>
运行结果