<html><head><script type="text/javascript">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="删除" onclick="deleteRow(this)"></td></tr><tr> <td>Row 2</td> <td><input type="button" value="删除" onclick="deleteRow(this)"></td></tr><tr> <td>Row 3</td> <td><input type="button" value="删除" onclick="deleteRow(this)"></td></tr></table></body></html>
1 回答

display_none
TA贡献52条经验 获得超13个赞
rowIndex返回某一行在表格的行集合中的位置,parentNode是父节点。
var i=r.parentNode.parentNode.rowIndex意思是定义一个变量i,值为r的父节点的父节点所在的一行。即是你这里的tr
添加回答
举报
0/150
提交
取消