如何删除表格中间插入行
JScript code
function addRow(obj) {
var num = obj.value; //num是提交的件数
var beginRow = obj.parentElement.parentElement.rowIndex;
var theTable = document.getElementById("fillTbl");
var dRow = document.getElementsByTagName("tr");
//alert(dRow.length);
if (dRow.length>0) {
for (var j=0; j <dRow.length; j++) {
if ("addCls" == dRow[j].name||"addClass" == dRow[j].className) {
theTable.deleteRow(dRow[j].rowIndex);
}
}
}
dRow = document.getElementsByTagName("td");
if (dRow.length>0) {
for (j=0; j <dRow.length; j++) {
if ("addCls" == dRow[j].name) {
theTable.deleteRow(dRow[j].parentElement.rowIndex);
}
}
}
dRow = document.getElementsByTagName("font");
if (dRow.length>0) {
for (j=0; j <dRow.length; j++) {
if ("addCls" == dRow[j].name) {
theTable.deleteRow(dRow[j].parentElement.parentElement.rowIndex);
if ("tr" == dRow[j].parentElement.parentElement.parentElement.tagName) {
//alert(dRow[j].parentElement.parentElement.parentElement.tagName);
theTable.deleteRow(dRow[j].parentElement.parentElement.parentElement.rowIndex);
}
}
}
}
var cellidx;
var newCell;
var newRow;
if (num>1) {
for (var i=num; i>=1; i--) {
// append new row to the end of the table
newRow = theTable.insertRow(beginRow+1); //theTable.rows.length);
// give the row its own ID
newRow.id = newRow.uniqueID;
newRow.name = "addCls"; // 为了修改件数可以删除添加的行,我用addCls作为name识别
newRow.className = "addClass"; //同样是为了删除下面添加的行,因为有2行就是删不掉
cellidx=0;
// an inserted row has no cells, so insert the cells
newCell = newRow.insertCell(cellidx);
newRow.bgcolor="#E7EDF5";
newRow.colspan="5";
// give this cell its own id
newCell.name = "addCls";
// display the row’s id as the cell text
newCell.align="center";
newCell.colspan="5";
newCell.bgcolor="#E7EDF5";
newCell.innerHTML = " <font name='addCls' color='#2D486C'>第"+i+"件的信息 </font>";
newRow = theTable.insertRow(beginRow+2); //theTable.rows.length);
newRow.className = "addClass";
newRow.id = newRow.uniqueID;
newRow.name = "addCls";
cellidx = 0;
newCell = newRow.insertCell(cellidx);
newCell.name = "addCls";
newCell.innerHTML =" <img src='image/weight.jpg'>";
cellidx++;
newCell = newRow.insertCell(cellidx);
newCell.name = "addCls";