JS Dynamic Add delete line code, very practical.
Have done a number of projects are used to add JS dynamic deletion of the application of the row, after writing a variety of programs, and finally sorted out the most convenient application of the program, for future use:
Here is the demo full code:
<title>ace test</title>
<script language= "JavaScript" >
var cgetrow=-99999;
function InsertRow () {
var NewRow = Document.all.ace_hidden_table.rows[0].clonenode (true); Clone a row
document.all ("NEWTB"). AppendChild (NewRow); Add a row that you just cloned
}
function GetRow () {
Get row index
Two parentelement respectively are TD and Tr,rowindex are the properties of TR
This.parentElement.parentElement.rowIndex
Cgetrow=window.event.srcelement.parentelement.parentelement.rowindex;
Delrow (Cgetrow);//click checkbox to delete Row directly.
}
function Delrow (iindex) {
Delete a row
if (iindex==-99999) {
Alert ("System prompt: No line number is selected!");
}else{
Newtb.deleterow (Iindex);
iindex==-99999;//will rowindex restore the default value.
}
}
</script>
<body class= "Dialog_body" >
<form method= "POST" onsubmit= "return Dosubmit" >
<table border= "1" width= "900" cellpadding= "0" cellspacing= "0" class= "table" >
<!--hide table, for cloning the line begin-->
<tbody id= "ace_hidden_table" style= "Display:none" >
<tr>
<td><input type= "checkbox" onclick= "GetRow ()"/></td>
<TD width= "16%" >
<select id= "pid" name= "Project" >
<option value= "" ></option>
<option value= "0" >
Person number
</option>
<option value= "1" >
Name
</option>
</select>
</td>
<TD width= "16%" >
<input id= "Result" type= "text" value= "readonly=" true ">
</td>
</tr>
</tbody>
</table>
<!--hide table for cloned line end-->
<table border= "1" width= "900" cellpadding= "0" cellspacing= "0" class= "table" >
<!--the area to insert a new row begin-->
<tbody id= "NEWTB" >
</tbody>
<!--insert a new row in the region end-->
</table>
<div align= "Right" style= "margin:10px;" >
<input type= "button" onclick= "InsertRow ()" value= "Add one line" >
<input type= "button" onclick= "Delrow (Cgetrow);" value= "delete one row" >
</div>
</form>
</body>