This code is dynamically adding a limited amount of text via jquery (5 in this case), and clearing the text content, using the After () method to append the element.
<!--The following is the start of the script code-->
Copy Code code as follows:
<script>
$ (document). Ready (function () {
var Spotmax = 5;//Limit the total number of add text elements
var Afterid = 0;//The ID of the element to append
var newid=1;//the ID of the newly generated text
if ($ (' table#vote '). Size () >= Spotmax) {}
$ ("#btnAddOption"). Click (function () {
afterid++;
newid=afterid+1;
Addspot (this, spotmax,afterid,newid);
});
});
//Add Option Method
function Addspot (obj, sm,afterid,newid) {
if ($ (' tr.spot '). Size () < SM) {
$ (' #vote_ ' +afterid). After (
' <tr id= ' vote_ ' +newid+ ' class= ' spot ' ><th> ' +afterid+ ' </th> ' +
' <td><input type= ' text "id=" Txtinput_ ' +afterid+ ' "class=" Input-text "value=" "size=" name= </td> ' +
' </tr> ');
$ (": text[id^= ' Txtinput_ ')"). Val ("Enter text ...");//give the new text the initial value
}
else{
alert ("can only add 5 votes!") ");
}
};
//Reset Options
$ ("Input#btnresetoption"). Click (function () {
$ (": text[id^= ' Txtinput_ ')"). Val ("");/Empty text content
});
</script>
<!--The following is the end of the script code-->
<!--The following is the beginning of the HTML code block-->
Copy Code code as follows:
<form method= ' post ' id= "UpdateForm" action= "Admin/vote/dovote" >
<table cellpadding=0 cellspacing=0 width= "100%" class= "Table_form" >
<tr>
<th width= "140" > Voting name </th>
<td>
<input type= "text" id= "txtname" name= "name" class= "Input-text" value= "" size=/> "
</td>
</tr>
<tr>
<th width= "140" > Voting description </th>
<td>
<textarea id= "Txtdescribe" class= "Input-text" name= "remark" cols= "></textarea>
"
</td>
</tr>
<tr>
<th width= "140" > Start time </th>
<td>
<input type= "text" id= "Datemin" class= "Input-text" value= "" Name= "StartDate" size= "" readonly= "ReadOnly" >
</td>
</tr>
<tr>
<th width= "140" > End time </th>
<td>
<input type= "text" id= "Datemax" class= "Input-text" name= "EndDate" "size=" readonly= "readonly"/>
</td>
</tr>
<tr>
<th width= "140" > Whether multiple selections </th>
<td>
<input type= "Radio" id= "Txtendtime" name= "Isselect" value= "0" size= ""/> Radio
<input type= "Radio" id= "Txtendtime" name= "Isselect" value= "1" size= "a"/> Multiple selection
</td>
</tr>
<tr id= "Vote_1" >
<th width= "140" > Voting options </th>
<td>
<input type= "button" id= "Btnaddoption" name= "btnaddoption" class= "button" value= "Add Options"/>
<input type= "reset" id= "btnresetoption" name= "btnresetoption" class= "button" value= "Reset Options"/>
</td>
</tr>
<tr id= "Save" >
<th></th>
<td align= "left" >
<input type= "Submit" id= "Btnsave" name= "btnsave" class= "button" style= "width:50px" value= "Save"/>
<input type= "Submit" id= "Btnclose" name= "btnclose" class= "button" style= "width:50px" value= "Cancel"/>
</td>
</tr>
</table>
</form>
<!--The following is the beginning of the HTML code block-->
The following are the effects of the operation: