ボタンをクリックして、表の行を追加/削除します.
14790 ワード
<
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();
"
>