本帖最后由 lddx09831 于 2011-02-24 15:43:10 编辑

解决方案 »

  1.   

    参考下面:<html>
    <head>
    <script type="text/javascript">
    function insCell()
      {
      var x=document.getElementById('tr2').insertCell(2)
      x.innerHTML="John"
      }
    </script>
    </head>
    <body><table border="1">
    <tr id="tr1">
    <th>Firstname</th>
    <th>Lastname</th>
    </tr>
    <tr id="tr2">
    <td>Peter</td>
    <td>Griffin</td>
    </tr>
    </table>
    <br />
    <input type="button" onclick="insCell()" value="插入单元"></body>
    </html>
      

  2.   

    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
            <title>增加Table行</title>
        </head>
        <script>
            function addRow(obj)
            {
            //添加一行
            var newTr = testTbl.insertRow();
            //添加两列
            var newTd0 = newTr.insertCell();
            var newTd1 = newTr.insertCell();
            //设置列内容和属性
            newTd0.innerHTML = '<input type=checkbox id="box4">'; 
            newTd1.innerText= '新加行';
            }
        </script>
        <body>
            <table id="testTbl" border=1>
                <tr id="tr1">
                    <td ><input type=checkbox id="box1"></td>
                    <td id="b">第一行</td>
                </tr>
                <tr id="tr2">
                    <td ><input type=checkbox id="box2"></td>
                    <td id="b">第二行</td>
                </tr>
                <tr id="tr3">
                    <td ><input type=checkbox id="box3"></td>
                    <td>第三行</td>
                </tr>
            </table>        
            <br />
            <input type="button" id="add" onclick="addRow();" value="Add Row" />
        </body>
    </html>