关于JS动态添加删除表格行的问题 请各位多多帮忙
这是我从网上找的代码,然后自己改了一些:
<script language= "javascript ">
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 add_Row(the_table) {
var the_row,the_cell;
var cur_rows=the_table.rows.length;
the_row=cur_rows==null?-1:(cur_rows);
var i=the_row-1;
var newrow=the_table.insertRow(i);//得到插入位置
the_cell=newrow.insertCell(0);
the_cell.innerHTML= " <center > 收件人 "+i;
the_cell=newrow.insertCell(1);
the_cell.innerHTML= " <center > <input name=A "+i+ " type=text size=13> ";
the_cell=newrow.insertCell(2);
the_cell.innerHTML= " <center > <INPUT type=button value=删除 onclick=del_row(myTable)> ";
}
function del_row(the_table){
var the_cell;
the_cell=get_Element(event.srcElement, "td ");
var index=the_cell.parentElement.rowIndex;
if(the_cell==null) return;
if(the_table.rows.length==1) return;
the_table.deleteRow(index);
var cell1= ' ';
var cell2= ' ';
for(var i=1;i <document.getElementById( 'myTable ').rows.length-2;i++)
{
try
{
&nb