Posted on 2006-07-27 14:31
lubaolin 阅读(346)
评论(0) 编辑 收藏
转贴:Andy.m 日期:2003-07-26 人气:35
<script>
function addRow(){
// 插入一行
myNewRow = document.all.myTable.insertRow();
var lenRow = document.all.myTable.rows.length; // 计算总行数
if(lenRow > 1){
var point = myNewRow.rowIndex; // 计算当前行位置
var lenCol = document.all.myTable.rows(0).cells.length; // 计算每行有几列
// 插入lenCol个td
for (i=0; i < lenCol; i++) {
document.all.myTable.rows(point).insertCell();
document.all.myTable.rows(point).cells(i).innerHTML = parseFloat(document.all.myTable.rows(point-1).cells(i).innerHTML) + lenCol;
}
}else if(lenRow == 1){
// 原来table是0行,初始化一行
for(i = 0; i < 10; i++){
document.all.myTable.rows(0).insertCell();
document.all.myTable.rows(0).cells(i).innerHTML = i;
}
}
}
function delRow(){
document.all.myTable.deleteRow();
}
</script>
<a href="javascript: addRow()">增加一行</a>
<a href="javascript: delRow()">减去一行</a>
<table name=myTable border=1 id=myTable>
</table>