创建管理表格(JS)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>增加Table行</title>
</head>
<script>
var sUserAgent = navigator.userAgent;
var isOpera = sUserAgent.indexOf("Opera") > -1;
var isIE = sUserAgent.indexOf("compatible") > -1 && sUserAgent.indexOf("MSIE") > -1 && !isOpera;
var i=0;
function addRow(obj)
{
//添加一行
var newTr = testTbl.insertRow(testTbl.rows.length-1);
//添加两列
var newTd0 = newTr.insertCell(0);
var newTd1 = newTr.insertCell(1);
//设置列内容和属性
newTd0.innerHTML = '<input type=checkbox id="box4">';
newTd1.innerHTML= '新加行'+i;
newTd1.id = 'ros'+i;
if(isIE)
newTd1.attachEvent("onclick",function(){alert(newTd1.innerHTML);});
else
newTd1.addEventListener("click",function(){alert(newTd1.innerHTML);},false);
i++;
}
function delRow(obj)
{
testTbl.deleteRow(testTbl.rows.length-2);
}
</script>
<body>
<table id="testTbl" border=1>
<tr id="tr1">
<td ><input type=checkbox id="box1"></td>
<td id="b1">第一行</td>
</tr>
<tr id="tr2">
<td ><input type=checkbox id="box2"></td>
<td id="b2">第二行</td>
</tr>
<tr id="tr3">
<td ><input type=checkbox id="box3"></td>
<td>第三行</td>
</tr>
</table>
<br />
<input type="button" id="add" onClick="addRow();" value="Add Row" />
<input type="button" id="del" onClick="delRow();" value="Del Row" />
</body>
</html>