如何给文本框命名。在表格中增加或删除一行。
程序代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www."> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>无标题文档</title> </head> <script language="javascript"> <!-- var theRowOfTheDynamicTable=null; function addRow(the_table){ if(the_table==null) return; var i=0; var the_row,the_cell; var row_index=-1; if(theRowOfTheDynamicTable==null){ theRowOfTheDynamicTable=new Array(); var baseTr=the_table.rows[0];//插入倒数第二行的内容 for(i=0;i<baseTr.cells.length;i++){ the_cell=baseTr.cells[i]; theRowOfTheDynamicTable[i]=the_cell.innerHTML; } } row_index=the_table.rows.length-1;//在第二行后面插入 var newrow=the_table.insertRow(row_index); for(i=0;i<theRowOfTheDynamicTable.length;i++){ the_cell=newrow.insertCell(i); the_cell.align="center"; the_cell.className="TdLeftBg"; the_cell.innerHTML=theRowOfTheDynamicTable[i]; } theRowOfTheDynamicTable=null; } function get_Element(the_ele,the_tag){ the_tag = the_tag.toLowerCase(); if(the_ele.tagName.toLowerCase()==the_tag) return the_ele; while(the_ele=the_ele.offsetParent){ if(the_ele.tagName.toLowerCase()==the_tag) return the_ele; } return(null); } function del_row(the_table){ if(the_table.rows.length<3){ alert("此行为保留行,不允许删除!"); return false; } var the_cell,the_row; var i=0; the_cell=get_Element(event.srcElement,"td"); if(the_cell==null) return; the_row=the_cell.parentElement.rowIndex; the_table.deleteRow(the_row); } --> </script> <body> <table id="myTable"width="800" align="center" border="1" > <tr> <td width="21%" rowspan="2"><input type="text" ></td> <td width="23%"><input type="text" ></td> <td width="18%"><input type="text"></td> <td width="18%"><input type="text"></td> <td width="20%" align="center"><input type="button" class="buttonstyle"value="删除" onClick="del_row(myTable)"></td> </tr> <tr > <td ><input type="text" ></td> <td ><input type="text" ></td> <td ><input type="text" ></td> <td align="center" ><input type="button" value="删除" onClick="del_row(myTable)"></td> </tr> <tr class="TdContent"> <td align="center" colspan="7"><input type="button" value="添加一行" onClick="addRow(myTable)"></td> </tr> </table> </body> </html>
如何给文本框取名。然后给一个表单,提交后。接收文本框的值时,又如何取值。