本文发表在 rolia.net 枫下论坛<script type="text/javascript">
var rowCount = 2;
function add() {
var namevalue = inputform.name.value;
var datevalue = inputform.birthyear.value;
rowCount++;
var newTR = document.createElement("<tr id="+rowCount+">");
var disTable = document.getElementById("display");
var nameText = document.createTextNode(namevalue);
var nameTD = document.createElement("<td>");
nameTD.appendChild(nameText);
var dateTD = document.createElement("<td>");
var dateText = document.createTextNode(datevalue);
dateTD.appendChild(dateText);
var checkTD = document.createElement("<td>");
var checkField = document.createElement("<INPUT type=checkbox name=isselect value="+rowCount+">");
checkTD.appendChild(checkField);
newTR.appendChild(nameTD);
newTR.appendChild(dateTD);
newTR.appendChild(checkTD);
disTable.tBodies.item(0).appendChild(newTR);
inputform.name.value="";
inputform.birthyear.value="";
}
function del() {
//var find = false;
var disTable = document.getElementById("display");
for (i=0;i< document.inputform.isselect.length;i++){
if (document.inputform.isselect[i].checked){
var temp = document.inputform.isselect[i];
delTD = temp.parentElement;
delTR = delTD.parentElement;
disTable.tBodies.item(0).removeChild(delTR);
}
}
}
</script>
<form name="inputform">
<TABLE id=display borderColor=#87ceeb cellSpacing=0 cellPadding=0 width="80%" align=center border=1>
<TR>
<TD align=middle><STRONG> Name</STRONG></TD>
<TD align=middle><STRONG> Birth Year</STRONG></TD>
<TD> <STRONG>Select</STRONG></TD></TR>
<TR>
<TD>Xiaoxiao</TD>
<TD>1972</TD>
<TD><INPUT type=checkbox name=isselect value=1></TD></TR>
<TR>
<TD>Dada</TD>
<TD>1972</TD>
<TD><INPUT type=checkbox name=isselect value=2></TD></TR></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="80%" align="center" border=0>
<TR>
<TD> </TD>
<TD> </TD></TR>
<TR>
<TD>Name: <INPUT name="name"></TD>
<TD>Birth Year: <INPUT name="birthyear"></TD></TR>
<TR>
<TD> </TD>
<TD> </TD></TR>
<TR>
<TD colspan=2 align=center>
<button onclick="add();">ADD</button> <button onclick="del();">DELETE</button> <button>SUBMIT</button></TD></TR></TABLE>
</form>更多精彩文章及讨论,请光临枫下论坛 rolia.net
var rowCount = 2;
function add() {
var namevalue = inputform.name.value;
var datevalue = inputform.birthyear.value;
rowCount++;
var newTR = document.createElement("<tr id="+rowCount+">");
var disTable = document.getElementById("display");
var nameText = document.createTextNode(namevalue);
var nameTD = document.createElement("<td>");
nameTD.appendChild(nameText);
var dateTD = document.createElement("<td>");
var dateText = document.createTextNode(datevalue);
dateTD.appendChild(dateText);
var checkTD = document.createElement("<td>");
var checkField = document.createElement("<INPUT type=checkbox name=isselect value="+rowCount+">");
checkTD.appendChild(checkField);
newTR.appendChild(nameTD);
newTR.appendChild(dateTD);
newTR.appendChild(checkTD);
disTable.tBodies.item(0).appendChild(newTR);
inputform.name.value="";
inputform.birthyear.value="";
}
function del() {
//var find = false;
var disTable = document.getElementById("display");
for (i=0;i< document.inputform.isselect.length;i++){
if (document.inputform.isselect[i].checked){
var temp = document.inputform.isselect[i];
delTD = temp.parentElement;
delTR = delTD.parentElement;
disTable.tBodies.item(0).removeChild(delTR);
}
}
}
</script>
<form name="inputform">
<TABLE id=display borderColor=#87ceeb cellSpacing=0 cellPadding=0 width="80%" align=center border=1>
<TR>
<TD align=middle><STRONG> Name</STRONG></TD>
<TD align=middle><STRONG> Birth Year</STRONG></TD>
<TD> <STRONG>Select</STRONG></TD></TR>
<TR>
<TD>Xiaoxiao</TD>
<TD>1972</TD>
<TD><INPUT type=checkbox name=isselect value=1></TD></TR>
<TR>
<TD>Dada</TD>
<TD>1972</TD>
<TD><INPUT type=checkbox name=isselect value=2></TD></TR></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="80%" align="center" border=0>
<TR>
<TD> </TD>
<TD> </TD></TR>
<TR>
<TD>Name: <INPUT name="name"></TD>
<TD>Birth Year: <INPUT name="birthyear"></TD></TR>
<TR>
<TD> </TD>
<TD> </TD></TR>
<TR>
<TD colspan=2 align=center>
<button onclick="add();">ADD</button> <button onclick="del();">DELETE</button> <button>SUBMIT</button></TD></TR></TABLE>
</form>更多精彩文章及讨论,请光临枫下论坛 rolia.net