WEB开发网
开发学院网页设计Html DOM动态删除TABLE多行 阅读

DOM动态删除TABLE多行

 2012-11-09 15:49:57 来源:WEB开发网   
核心提示: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>DOM动态删除TABLE多行</titl

 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>DOM动态删除TABLE多行</title>
<script type="text/javascript">
function $(objId){
return document.getElementById(objId);
}
function del_tbl(tblN,ckN){
var ck = document.getElementsByName(ckN);
var tab = $(tblN);
var rowIndex;
for(var i=0;i<ck.length;i++){
if(ck[i].checked){
rowIndex = ck[i].parentNode.parentNode.rowIndex;

alert(rowIndex);
tab.deleteRow(rowIndex);
i = -1;
}
}
}</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="253" border="1" align="center" id="list">
<tr>
<td><input type="checkbox" name="cb_k" id="cb_k" /></td>
<td>2</td>
<td>3</td>
</tr>
<tr id="tr1">
<td width="28" height="41"><input type="checkbox" name="del" id="del" /></td>
<td width="124"><div align="center">第一行 </div></td>
<td width="79"><div align="center">1</div></td>
</tr>
<tr id="tr2">
<td height="36"><input type="checkbox" name="del" id="del" /></td>
<td><div align="center">第二行 </div></td>
<td><div align="center">2</div></td>
</tr>
<tr id="tr3">
<td height="40"><input type="checkbox" name="del" id="del" /></td>
<td><div align="center">第三行 </div></td>
<td><div align="center">3</div></td>
</tr>
<tr id="tr4">
<td height="37"><input type="checkbox" name="del" id="del" /></td>
<td><div align="center">第四行 </div></td>
<td><div align="center">4</div></td>
</tr>
<tr id="tr5">
<td height="50"><input type="checkbox" name="del" id="del" /></td>
<td><div align="center">第五行 </div></td>
<td><div align="center">5</div></td>
</tr>
<tr>
<td colspan="3">
<div align="center">
<input type="button" name="btn_del" id="btn_del" value="删 除" onclick="del_tbl('list','del')"/>
</div></td>
</tr>
</table>
</form>
</body>
</html>

Tags:DOM 动态 删除

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接