`
aideehorn
  • 浏览: 256470 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

动态添加表格

阅读更多

<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>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics