function addRow(){
var tblObj = document.getElementById("table1");
if(tblObj.rows){
alert(tblObj.rows.length);
}else{
alert('aaa');
}
//追加行
var newRow = tblObj.insertRow();
newRow.style.display = "";
var cellNum = tblObj.rows[0].cells.length;//追加列
for (colIndex = 0; colIndex < cellNum; colIndex++) {
var newCell = newRow.insertCell();
initTblCell(newCell);
}
}
function initTblCell(cell){
var lastCell = document.getElementById("table1").rows[0].cells[cell.cellIndex];
cell.innerHTML = lastCell.innerHTML;
alert(cell.innerHTML);
if (cell.children != null && cell.children.length > 0) {
for(childIndex = 0; childIndex < cell.children.length; childIndex++) {
var child = cell.children[childIndex];
switch(child.type) {
case "text":
child.value = "";
break;
case "checkbox":
child.value = "";
child.checked = false;
break;
}
}
}
cell.className = lastCell.className;
cell.align = lastCell.align;
cell.height = lastCell.height;
}
function buttonFun(){
var obj= document.getElementsByName("text4");
for(i=1;i<obj.length;i++){
alert(obj[i].value);
}}
function dellRow(){
var obj= document.getElementById("table1");
var objRow=obj.rows.length-1;
alert(objRow);
if(objRow != 0){
obj.deleteRow(objRow);
}}  <table id="table1" name="table1" width="300">
        <tr style="display:none">
    <td width="100">
    <input type="button" name="testBtn4" value="button" onclick=""/>
    </td>
    <td width="100">
    <input type="text" name="text4"  id="text4"/>
    </td>
    <td width="100">
    123
    </td>
    </tr>
    
    <tr>
    <td width="100">
    <input type="button" name="testBtn4" value="button" onclick="toExcel_Page()"/>
    </td>
    <td width="100">
    <input type="text" name="text4"  id="text4"/>
    </td>
    <td width="100">
    123
    </td>
    </tr>
    </table>
    <input type="button" name="testAdd" id="testAdd" value="AddRow" onclick="addRow()"/>
    <input type="button" name="testAdd" id="testAdd" value="DellRow" onclick="dellRow()"/>
    <input type="button" name="testAdd2" id="testAdd2" value="GetTextValue" onclick="buttonFun()"/>
你的就是添加和删table的 问题,上面的就是,