JSP using JavaScript dynamic insert delete input box implementation code
- 2020-03-30 03:21:54
- OfStack
JavaScript code:
Key code in a Jsp page
Set the id of the table so that JavaScript can recognize the table
<script language="javascript">
function addrows(){
var len = optionlist.rows.length; //I get the number of rows in the table
var obj = optionlist.insertRow(len);//Insert on the last line
obj.insertCell(0);
obj.cells(0).innerHTML=" options " + (len+1) + " : <input type=text name=option size=28>";
}
function deleterow(){
var len = optionlist.rows.length;
if(len <= 1) {
alert(" At least one option ");
}
else {
optionlist.deleteRow(len-1);//Delete the last term
}
}
function getOptionCount(){
return optionlist.rows.length;
}
</script>
Key code in a Jsp page
<input type="button" id="bt1" value=" Add a option " onClick="addrows();">
<input type="button" id="bt2" value=" Delete options " onClick="deleterow();">
Set the id of the table so that JavaScript can recognize the table
<table id="optionlist">
</table>