<input type="button" value="插入" onclick="insert_row()"> <table name='tbl' id="tbl" border="1" width=300> 
</table> 
<script> 
var i=0 
function insert_row(){ 
i++ 
R=tbl.insertRow() 
C=R.insertCell() 
C.innerHTML="<input type='file' name='file' >" 
C=R.insertCell() 
C.innerHTML="文件"+i 
C=R.insertCell() 
C.innerHTML="<input type='button'  value='删除' onclick='tbl.deleteRow("+(i-1)+")'>" } 
</script> 

<script>
function creates(){
newiframes=document.createElement("TABLE")
newiframes.id="t1"
newiframes.width="100"
newiframes.border="1"
newiframes.height="100"
newiframes.align="left"
newiframes.style.background="red"
newiframes.insertRow()
newiframes.rows[0].insertCell()
document.body.insertBefore(newiframes)
}
</script>
<body>
<input type=button value='加一个表格' onclick=creates()><br>
</body>

解决方案 »

  1.   

    <table border=1 id="tbl"></table>
    <input type="button" value="addRow" onclick="addRow()">
    <input type="button" value="deleteRow" onclick="deleteRow()">
    <script>
    function addRow(){
    var newTr=tbl.insertRow(),newTd
    newTd=newTr.insertCell()
    newTd.innerText="abc";
    newTd=newTr.insertCell()
    newTd.innerText="xyz";
    }function deleteRow(){
    if(tbl.rows.length ==0) return
    tbl.deleteRow(tbl.rows.length - 1)
    }
    </script>