<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<SCRIPT type="text/javascript">
function numberCells()
{
var count=0;
for (i=0; i < document.all.Tab.rows.length; i++)
{
for (j=0; j < document.all.Tab.rows(i).cells.length; j++)
{
document.all.Tab.rows(i).cells(j).innerText = count;
count++;
}
}
}
function tb_addnew()
{
var ls_t=document.all("Tab")
maxcell=ls_t.rows(0).cells.length;
mynewrow = ls_t.insertRow();
for(i=0;i <maxcell;i++)
{
mynewcell=mynewrow.insertCell();
mynewcell.innerText="a"+i;
}
}
function tb_delete()
{
var ls_t=document.all("Tab");
ls_t.deleteRow() ;
}
</SCRIPT>
<html>
<head>
<script type="text/javascript">
function addRow(TabId){
//获取要插入行的表格
var table = document.getElementById(TabId);
//在最后一行插入一行
var newRow = table.insertRow(table.rows.length);
//在该行插入单元格
var newCel1 = newRow.insertCell(0);
var newCel2 = newRow.insertCell(1);
var newCel3 = newRow.insertCell(2);
newCel1.innerHTML = "第一列";
newCel2.innerHTML = "第二列";
newCel3.innerHTML = "第三列";
}
</script>
</head>
<body>
<center>
<table id="Tab" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>
第一列
</td>
<td>
第二列
</td>
<td>
第三列
</td>
</table>
<br>
<input type="button" οnclick="addRow('Tab');" value="插入行"/>
<input type="button" οnclick="tb_delete();" value="删除行"/>
<input type="button" οnclick="tb_addnew();" value="添加行"/>
<input type="button" οnclick="numberCells();" value="显示单元个数"/>
</center>
</body>
</html>