日期:2014-05-16 浏览次数:20400 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>动态添加删除表格---不支持火狐</title>
</head>
<script type="text/javascript" language="javascript">
? var count=1;
? function addTR(){
????? var imguptb = document.getElementById("imguptb");??
?? var row = imguptb.insertRow();
?? //添加名称
?? cell= row.insertCell();
?? cell.innerHTML="<input name='name"+count+"' class='name_input' id='name_"+count+"' type='text' maxlength='20' />"
?? //添加删除链接
?? cell= row.insertCell();
?? cell.innerHTML= "[<a href='#' onclick='deletePic(this);'>删除</a>]";
?? count++;
? }
//删除一行
function deletePic(tr_a){
var imguptb = document.getElementById("imguptb");
var trobj = tr_a.parentNode.parentNode;
imguptb.deleteRow(trobj.rowIndex);
}
</script>
<body>
<table height="31" border="0" cellpadding="0" cellspacing="2" id="imguptb">
<tr>
<td width="200"><strong>名称</strong></td>
<td width="70"><strong>操作</strong></td>
</tr>
</table>
<table id="table2"><tr><td><input type="button" id ="addbut" name="addbut" onClick="addTR();" value="增加一行数据"/></td></tr></table>
?
</body>
</html>