<
table width
=
"
100%
"
border
=
"
1
"
id
=
"
tb
"
>
< tr >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
</ tr >
< tr >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
</ tr >
< tr >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
</ tr >
< tr >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
</ tr >
</ table >
< p >
< script >
/*
操作表格,为表格添加行,删除行操作
*/
function delrow(){
var i = tb.rows.length;
tb.deleteRow(i - 1 );
}
function addrow(){
var tr = document.createElement( ' tr ' );
var cellsNum = tb.rows[ 0 ].cells.length;
for (var j = 0 ; j < cellsNum ; j ++ ){
var td = document.createElement( ' td ' );
td.innerHTML = ' test ' ;
tr.appendChild(td);
}
tb.tBodies[ 0 ].appendChild(tr);
}
</ script >
< input type = " submit " name = " Submit " value = " 删除 " onClick = " delrow(); " >
< input type = " submit " name = " Submit " value = " 添加 " onClick = " addrow(); " >
< tr >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
</ tr >
< tr >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
</ tr >
< tr >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
</ tr >
< tr >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
< td >& nbsp; </ td >
</ tr >
</ table >
< p >
< script >
/*
操作表格,为表格添加行,删除行操作
*/
function delrow(){
var i = tb.rows.length;
tb.deleteRow(i - 1 );
}
function addrow(){
var tr = document.createElement( ' tr ' );
var cellsNum = tb.rows[ 0 ].cells.length;
for (var j = 0 ; j < cellsNum ; j ++ ){
var td = document.createElement( ' td ' );
td.innerHTML = ' test ' ;
tr.appendChild(td);
}
tb.tBodies[ 0 ].appendChild(tr);
}
</ script >
< input type = " submit " name = " Submit " value = " 删除 " onClick = " delrow(); " >
< input type = " submit " name = " Submit " value = " 添加 " onClick = " addrow(); " >