<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 閱讀(467)
評論(0) 編輯 收藏 所屬分類:
javascript