javascript table 增加删除行

<html>
<head>
<script type="text/javascript">
function deleteRow(r)
{
var i=r.parentNode.parentNode.rowIndex
document.getElementById('myTable').deleteRow(i)
}

function insertRowInTable(){
var table = document.getElementById("myTable");
var newRow = table.insertRow(-1);
newRow.insertCell().innerHTML = newRow.rowIndex;
newRow.insertCell(-1).innerHTML = "<input type='button' value='删除' onclick='deleteRow(this)'>";
}
</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>
<input type="button" onclick="insertRowInTable();" value="插入一行" />
</body>
</html>

你可能感兴趣的:(JavaScript,java)