Here, jquery is used. Key Code As follows:
Copy code The Code is as follows: // Add a data row;
Function addrow (){
VaR VTB = $ ("# tbdata"); // obtain the jquery object of table id = tbdata.
// All data rows have A. caserow class to get the size of the Data row
VaR vnum = $ ("# tbdata TR"). Filter (". caserow"). Size () + 1; // number of data rows in the table
VaR VTR = $ ("# tbdata # trdatarow1"); // obtain the first row of data in the table.
VaR vtrclone = VTR. Clone (true); // create the first row of the copy object vtrclone
Vtrclone [0]. id = "trdatarow" + vnum; // set the first ID as the index of the current region; prevent duplicate rows with multiple IDS as trdatarow1; add one at a time;
Vtrclone. appendto (VTB); // Add the copy Cell Object to the bottom of the table.
}
This method mainly uses the jquery clone function to clone a row copy of a table. Then add it to the original table.
key code of the deletion method: copy Code the code is as follows: var vnum =$ (" # tbdata TR "). filter (". caserow "). size () + 1; // number of data rows in the table;
If (vnum <= 2)
{< br> alert ('Leave at least one line');
return;
}< br> var vbtndel =$ (this ); // obtain the clicked Button Object
var VTR = vbtndel. parent ("TD "). parent ("TR"); // get the parent tr object;
If (VTR. ATTR ("ID") = "trdatarow1")
{< br> alert ('the first line cannot be deleted! '); // The first row is the basis for cloning and cannot be deleted
return;
}else {
Vtr. remove ();
}