js動的に削除行を追加します.

1719 ワード

            ,  ,google  ,      ,       ,      。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 </HEAD>

 <BODY>
	<table border="1" id="mytb">
	</table>
	<input type="button" value="add" onclick="add()">&nbsp;&nbsp;&nbsp;
	<input type="button" value="del()" onclick="del()">&nbsp;&nbsp;
 </BODY>
</HTML>
<script>
var i=0;
function add(){
	var mytb=document.getElementById("mytb");
	var newRow = mytb.insertRow();
	i++;
	var newTd0 = newRow.insertCell();
    var newTd1 = newRow.insertCell();
	var newTd2 = newRow.insertCell();
    newTd0.innerHTML="<input type='checkbox' name='chbox'>";
	newTd1.innerHTML="  "+i;
	newTd2.innerHTML="  "+i;
}
function del(){
	var chboxs = document.getElementsByName("chbox");
	var mytb=document.getElementById("mytb");
	for(var i=chboxs.length;i>0;i--){
		var e=chboxs[i-1];
		if(e.checked){
			//      0   
			mytb.deleteRow(i-1);
		}
	}
}
</script>