<Script language="JavaScript">
function addRow()
{
MainTab.border='1';
newRow=MainTab.insertRow()
newCell=newRow.insertCell()
newCell.width='50%';
newCell.innerHTML="<input style='width:100%' type=text>"
newCell=newRow.insertCell()
newCell.width='50%';
newCell.innerHTML="<input style='width:100%' type=text>"
}
function delRow()
{
window.MainTab.deleteRow(0)
//它是从0开始的,最大值是MainTab.rows.lenth-1
}
</Script>
</Head>
<Body>
<Table id=MainTab width=100%>
</Table>
<input type=Button Value="增加" onClick="addRow()">
<input type=button value="删除" onClick="delRow()">
</Body>
你试试看吧,可以的,不知道是不是你要的效果
function addRow()
{
MainTab.border='1';
newRow=MainTab.insertRow()
newCell=newRow.insertCell()
newCell.width='50%';
newCell.innerHTML="<input style='width:100%' type=text>"
newCell=newRow.insertCell()
newCell.width='50%';
newCell.innerHTML="<input style='width:100%' type=text>"
}
function delRow()
{
window.MainTab.deleteRow(0)
//它是从0开始的,最大值是MainTab.rows.lenth-1
}
</Script>
</Head>
<Body>
<Table id=MainTab width=100%>
</Table>
<input type=Button Value="增加" onClick="addRow()">
<input type=button value="删除" onClick="delRow()">
</Body>
你试试看吧,可以的,不知道是不是你要的效果
如用鼠標動態控制並可改變大小就有挑戰性了
<body>
<script>
var tbl, tbody, tr, td, text, i, max;
max = 10;
var theDoc = document;
var theBody = theDoc.body;
tbl = theDoc.createElement("TABLE");
tbl.border = "1";
tbody = theDoc.createElement("TBODY");
tbl.insertBefore(tbody, null);
theBody.insertBefore(tbl, null);
for (i=0; i<max; i++) {
tr = theDoc.createElement("TR");
td = theDoc.createElement("TD");
text = theDoc.createTextNode("Text"+i);
td.insertBefore(text, null);
tr.insertBefore(td, null);
tbody.insertBefore(tr, null);
}
</script>
</body>
</html>
http://fason.nease.net/上有例子