你应该在添加留言时动态添加Table的行和列,然后再在新加的单元格里赋值。

解决方案 »

  1.   

    document.getElementById("newNickname")每次添加的时候都是在改变同一个div的值啊
      

  2.   


    对,就是这个样子,实现动态添加<tr> <td></td>...</tr>可是怎么实现动态添加?刚开始学JS不久,,,,可能要用得appendChild()这个方法,
    可是实现真就不知道怎么做了,,,,
      

  3.   

    tr是在 tbody下的. 不是 table下的  - -
      

  4.   

    给你一个例子:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>表格</title>
    </head>
    <body>
    <button onclick="fun()">插入行</button>
    <table border="1" id="tab">
    </table>
    <script type="text/javascript">
    function fun()
    {
        var tb = document.getElementById("tab").tBodies[0];
        var row = tb.insertRow(0);
        var cell = row.insertCell(0);
        cell.innerHTML = "hello";
        cell = row.insertCell(1);
        var ipt = document.createElement("input");
        ipt.type = "text";
        cell.appendChild(ipt);
    }
    </script>
    </body>
    </html>
      

  5.   

    5楼FF不通过<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>表格</title>
    </head>
    <body>
    <button onclick="fun()">插入行</button>
    <table border="1" id="tab">
    <tbody>
    </tbody>
    </table>
    <script type="text/javascript">
    function fun()
    {
        var tb = document.getElementById("tab").tBodies[0];
        var row = tb.insertRow(0);
        var cell = row.insertCell(0);
        cell.innerHTML = "hello";
        cell = row.insertCell(1);
        var ipt = document.createElement("input");
        ipt.type = "text";
        cell.insertBefore(ipt,null);
    }
    </script>
    </body>
    </html>