newRow=table1.insertRow(table1.rows.length);
    newRow.id="r"+table1.rows.length;
    c1=newRow.insertCell(0);
    c1.id="r"+table1.rows.length+"c0";
    textname="tr"+table1.rows.length+"c0";
    c1.innerHTML="<input type=text name="+textname+" id="+c1.id+" >"

解决方案 »

  1.   

    <table id="table1" cellspacing=1 bgcolor=black>
    <tr bgcolor=#ffcc00>
    <td>111111
    <td>222222
    </table><br>
    <input type=button value="add" onclick=add()>
    <script>
    function add()
    {
        newRow=table1.insertRow(table1.rows.length);
        newRow.bgColor="#ffcc00";
        c0=newRow.insertCell(0);
        c1=newRow.insertCell(1);
        c0.innerText="dsa321";
        c1.innerHTML="<input type='button' value='delete row' onclick='del(this.id)' id=1>";
    }
    function del(id)
    {
        table1.deleteRow(id);
    }
    </script>