<!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML> <Head> <title>New Document</title> <styletype= "Text/css">Table{Border-collapse:collapse;Border:None;width:200px; }TD{Border:Solid #000 1px; } </style> <Script> //gets the current domain at index, (is the number of XXX) functionGetelementorder (Field,tableid) {varInputs=Document.getelementsbyname (field.name); varLen=inputs.length; varIndex= 0; for (varI= 0; I<Len; I++){ if(Inputs==field) {Index=i; Break; } } returnindex; } functionInsertRow (tableid,table_data) {//Get Tbody (create a table will have a default tbody load tr TD here to get tale a tbody) varOtbody=document.getElementById (tableid). tbodies[0];//This is equivalent to the item (0) in JS using the array ordinal directly called the Visible JavaScript authoritative guide P368 varOtbodydata=document.getElementById (table_data). tbodies[0]; varLen=oTBODYData.rows.length; //Traverse data Row for ( varI= 0; I<=Len; I++) {otbody.appendchild (Otbodydata.rows[i].clonenode (true)); } } functionDeleteRow (field,targettable) {varFindex=Getelementorder (Field)-1;//minus 1 Here is because a row in SourceTable is hidden.document.getElementById (targettable). DeleteRow (Findex); } </Script> </Head> <Body> <TableID= "Table_data"class= "Data"style= "Display:none"> <TR> <TD><inputtype= "text"name="">1</TD> <TD><inputtype= "text"name= "2"></TD> <TD><inputtype= "text"></TD> <TD><inputtype= "button"value= "Delete"onclick= "DeleteRow (this, ' table_list ');"></TD> </TR> </Table> <TableID= "Table_list"class= "List"> <TR> <TD>Age<TD> <TD>Gender</TD> <TD><inputtype= "button"name= "Del"onclick= "DeleteRow (this)"></TD> <TD><inputtype= "button"value= "Add"name= "Insert"onclick= "InsertRow (' table_list ', ' Table_data ')"></TD> </TR> </Table> </Body></HTML>
method is very common, do not knock once who rush to say that they will.
JS Operation table