<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "><ptml xmlns=" http://www.w3.org/1999/xhtml "><pead><meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/><title> Modify order </title><style type=" Text/css ">body{font-size:13px;line-height : 25px;} table{border-top:1px solid #333; border-left:1px solid #333; width:400px;} td{border-right:1px solid #333; border-bottom:1px solid #333; text-align:center;}. Title{font-weight:bold;background-color: #cccccc;} Input text{width:100px;} </style><script type= "Text/javascript" >function AddRow () {var Addtable=document.getelementbyid ("Order" ); var row_index=addtable.rows.length-1; The position of the newly inserted row in the table var newrow=addtable.insertrow (row_index); Insert New line newrow.id= "Row" +row_index; Sets the ID of the newly inserted row var col1=newrow.insertcell (0); Col1.innerhtml= "Anti-fatigue magic titanium collar"; var Col2=newrow.insertcell (1); Col2.innerhTml=row_index; var Col3=newrow.insertcell (2); Col3.innerhtml= "¥49.00"; var Col4=newrow.insertcell (3); var str= "<input name= ' del" +row_index+ "' type= ' button ' value= ' delete ' onclick=\ ' delrow (' Row ' +row_index+ ') \"/> <input id= ' edit ' +row_index+ ' type= ' button ' value= ' Modify ' onclick=\ ' Editrow (' Row ' +row_index+ ') \ '/> '; Col4.innerhtml=str;} function Delrow (rowId) {var Row=document.getelementbyid (rowId). RowIndex; Delete the position in the table where the row is located document.getElementById ("Order"). DeleteRow (row); }function Editrow (rowId) {var Row=document.getelementbyid (rowId). RowIndex; Modify the position in the table where the row is located var Col=document.getelementbyid (rowId). Cells;var text=col[1].innerhtml;col[1].innerhtml= "<input Name= ' num ' +row+ "' style= ' width:40px; ' type= ' text ' value= '" +text+ "'/>"; col[3].lastchild.value= "OK"; col[3]. Lastchild.setattribute ("onclick", "Uprow ('" +rowid+ ")"); function Uprow (rowId) {var Row=document.getelementbyid (rowId). RowIndex; Modify the position in the table where the row is located var Col=document.getelementbyid (rowId). Cells;var Text=col[1]. firstchild.value;col[1].innerhtml=text;col[3].lastchild.value= "Modify"; Col[3].lastchild.setattribute ("onclick", " Editrow (' "+rowid+" ') ");} </script></pead><body><table border= "0" cellspacing= "0" cellpadding= "0" id= "order" > <tr class= "title" > <td> Product name </td> <td> quantity </td> <td> price </td> <td> operation </t d> </tr> <tr id= "Del1" > <td> non-slip leather casual shoes </td> <td>12</td> <TD>¥568.50&L t;/td> <td><input name= "Rowdel" type= "button" value= "delete" onclick= ' Delrow ("Del1") '/> <input id= ' Ed It1 "type=" button "value=" Modify "onclick= ' Editrow (" Del1 ") '/></td> </tr> <tr> <td colspan=" 4 "St Yle= "height:30px;" > <input name= "addorder" type= "button" value= "Add Order" onclick= "AddRow ()"/></td> </TR></TABLE&G T;</body></ptml>
JavaScript Table Modification