日期:2014-05-16 浏览次数:20296 次
<html>
<body>
<table width="200" border="1" id="tb">
? <tr id="r1">
??? <td><input type="checkbox" name="ck" value="1"></td>
?<td>abc</td>
? </tr>
</table>
<p>
? <input type="button" onClick="add();" value="add"/>
?? <input name="button" type="button" onClick="deletes();" value="delete"/>
</p>
</body>
?
<script language="javascript">
?var tb=document.getElementById("tb");
?var i=2;
??? function add()
?{
? ?var mytr=tb.insertRow();
? ?mytr.setAttribute("id","r"+i);
? ?var mytd_1=mytr.insertCell();
??var mytd_2=mytr.insertCell();
??mytd_1.innerHTML="<input type='checkbox' name='ck' value='"+i+"'>";
??mytd_2.innerText="abc"+i;
??i++;
??
?}
?
?function deletes()
?{
???
??? var ok=document.getElementsByName("ck");
?????? for(var k=0;k<ok.length;k++)
??? {
??????????? if(ok[k].checked==true)
??????????? {
??????????????? tb.deleteRow(k);
??????????????? k=k-1;
??????????? }
?????? }
?}
</script>
</html>