<html>
<head>
<script>
function test(){
var ls_t = window.document.all("table1"); //获得id为talbe1的对象
var trIndex = window.document.all("tr1");
maxcell=ls_t.rows(0).cells.length;
mynewrow = ls_t.insertRow(); //添加新行
if(!trIndex.value) {
trIndex.value = 0;
}
trIndex.value = parseInt(trIndex.value) + 1;
mynewrow.setAttribute("id","tr" + trIndex.value); //添加一个变量为id
mynewcell=mynewrow.insertCell(); //添加新列
mynewcell.setAttribute("align","center");
mynewcell.innerHTML="1";
mynewcell=mynewrow.insertCell();
mynewcell.setAttribute("align","center");
mynewcell.innerHTML="test";
mynewcell=mynewrow.insertCell();
mynewcell.setAttribute("align","center");
mynewcell.innerHTML="25";
}
</script>
</head>
<body>
<a href="javascript:test()">添加新行新列</a>
<table id="table1" border="1">
<tr id="tr1">
<td>序号</td>
<td>姓名</td>
<td>年龄</td>
</tr>
</table>
</body>
</html>
posted on 2012-02-28 09:41
kxbin 阅读(460)
评论(0) 编辑 收藏 所属分类:
javascript