`

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>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics