zoukankan      html  css  js  c++  java
  • 添加减少表格列

    <html>
    <head>
    <title></title>
    <script src="jquery-1.7.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    function addCol() {
    $th = $("<th>增加的列头</th>");
    $col = $("<td>增加的列</td>");
    $("#tab1>thead>tr").append($th);
    $("#tab1>tbody>tr").append($col);
    }
    function delCol() {
    //移除最后一列
    $("#tab1 tr :last-child").remove();
    //移除第一列
    //$("#tab1 tr :first-child").remove();
    //移除指定的列, 注:这种索引从1开始
    //$("#tab1 tr :nth-child(2)").remove();
    //移除第一列之外的列
    //$("#tab1 tr :not(:nth-child(1))").remove();
    }

    </script>
    </head>
    <body>
    <input id="Button1" type="button" onclick="addCol()" value="增加列" />
    <input id="Button2" type="button" onclick="delCol()" value="减少列" />
    <table id="tab1" border="1" style=" 200px;">
    <thead>
    <tr>
    <th>
    &nbsp;
    Id</th>
    <th>
    &nbsp;
    Name</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>
    &nbsp;
    1</td>
    <td>
    &nbsp;
    叶子</td>
    </tr>
    <tr>
    <td>
    &nbsp;
    2</td>
    <td>
    &nbsp;
    王子</td>
    </tr>
    </tbody>
    </table>
    </body>
    </html>

  • 相关阅读:
    每周必写
    每周必写
    每周必写
    感想及阅读内容
    阅读内容及感想
    每周感想和阅读内容
    每周感想及阅读内容
    每周感想及阅读内容
    分答
    每周感想及阅读内容
  • 原文地址:https://www.cnblogs.com/chai-blogs/p/5291085.html
Copyright © 2011-2022 走看看