Adding the deletion code based on the jquery table is a dynamic increase in the deletion table row effect code. Share to everyone for your reference. Specifically as follows:
The screenshot of the running effect is as follows:
The specific code is as follows:
HTML code:
<div style= "width:720px;margin:20px auto;" > <table id= "tab11" style= "Display:none" > <tbody> <tr> <td height= "Al" ign= "center" > <input type= "text" name= "NO" size= "2" value= "1"/> </td> <td align= "center" > <input type= "text" name= "Start_end_time"/> </td> <td Align = "center" > <input type= "text" name= "unit_department"/> </td> <td align= "ce Nter "> <input type=" text "name=" post "/> </td> <td> <input Type= "button" id= "Button1" onclick= "deltr (This)" value= "delete line"/> </td> </tr> </tbody > </table> <input type= "button" id= "BTN_ADDTR" value= "Add lines"/> <table id= "dynamictable" width= "70 0 "border=" 0 "cellspacing=" 0 "cellpadding=" 0 "> <thead> <tr> <TD height= "align=" "Center" bgcolor= "#CCCCCC" >ID</td> <td align= "center" bgcolor= "#CCCCCC" > Start/Start time & lt;/td> <td align= "center" bgcolor= "#CCCCCC" > Unit/Department </td> <TD align= "center bgcolor=" #C CCCCC "> Position </td> <td></td> </tr> </thead> <tbody> &L t;tr> <td height= "align=" center "> <input type=" text "name=" NO "size=" 2 "value=" 1 "/>
; </td> <td align= "center" > <input type= "text" name= "Start_end_time"/> </ td> <td align= "center" > <input type= "text" name= "unit_department"/> </TD&G
T
<TD align= "center" > <input type= "text" name= "post"/> </td> <td>
<input type= "button" id= "Button2" onclick= "deltr (This)" value= "delete line"/> </td> </tr> </tbody> </table> </div>
JS Code:
$ (function () {
var show_count =; The number of bars to display
var count = 1; Increment start value, here is your ID
$ ("#btn_addtr"). Click (function () {
var length = $ ("#dynamicTable tbody tr"). Length;
alert (length);
if (length < Show_count) //Click Time, if the current number is less than the increment end condition
{
$ ("#tab11 tbody tr"). Clone (). Appendto ("# DynamicTable tbody "); Add a row after the table
Changeindex ();//Update line number
}
}
); function Changeindex () {
var i = 1;
$ ("#dynamicTable tbody tr"). each (function () {//Cyclic tab TBODY TR
$ (this). Find ("Input[name= ' NO ')"). Val (i++); Update line number
});
function deltr (OPP) {
var length = $ ("#dynamicTable tbody tr"). Length;
alert (length);
if (length <= 1) {
alert ("Keep at least one row");
} else {
$ (OPP). Parent (). Parent () remove ();//removing Current line
Changeindex ();
}
Hopefully this article will help you learn about JavaScript as a programming program.