<!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=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
var tbl=document.createElement("table");
tbl.border="1";
function addRows()
{
var boy=document.getElementsByTagName("body")[0];
if(getRows()>0){
var tr = document.createElement("tr");
for(var i=1;i<=getCols();i++){
var td=document.createElement("td");
td.innerHTML=getRows()+1;
td.innerHTML+=i;
tr.appendChild(td);
}
}
else
{
var tr=document.createElement("tr");
var td=document.createElement("td");
td.innerHTML='11';
tr.appendChild(td);
}
tbl.appendChild(tr);
boy.appendChild(tbl);
}
function addCols()
{
if(getRows()>0){
for(var i=1;i<=document.getElementsByTagName("tr").length;i++)
{
var td=document.createElement("td");
td.innerHTML=i;
if(i==1)
td.innerHTML+=getCols()+1;
else
td.innerHTML+=getCols();
document.getElementsByTagName("tr")[i-1].appendChild(td);
}
}
else
addRows();
}
function getRows()
{
return document.getElementsByTagName("tr").length;
}
function getCols()
{
return document.getElementsByTagName("tr")[0].getElementsByTagName("td").length;
}
</script>
</head>
<body>
<button onclick="addRows()">加行</button><button onclick="addCols()">加列</button>
</body>
</html>