zoukankan      html  css  js  c++  java
  • DOM增删操作(创建删除表格)

    <!DOCTYPE html>
    <html>

    <head>
    <meta charset="UTF-8">
    <title></title>
    <script>
    //创建table
    function createTable(){
    var tab = document.createElement('table');
    tab.border = 1;
    tab.id = 'mtab';
    var caption = tab.createCaption();
    caption.innerHTML = 'helle';

    for(var i = 0;i<5;i++){
    var tr = tab.insertRow(i);
    for(var j=0;j<4;j++){
    var td = tr.insertCell(j);
    td.innerHTML = ''+i+j;
    }
    }

    document.getElementById('test').appendChild(tab);
    }

    //删除行
    function deleterow(){
    var tab = document.getElementById('mtab');
    if(tab.rows.length > 0){
    tab.deleteRow(tab.rows.length - 1);
    }
    }


    //删除列
    function deletecell(){
    var tab = document.getElementById('mtab');
    var row = tab.rows[tab.rows.length - 1];
    if(row.cells.length > 0){
    row.deleteCell(row.cells.length -1);
    }
    }


    </script>
    </head>

    <body id="test">
    <button value="1" onclick="createTable()">createTable</button><br />
    <button value="2" onclick="deleterow()">deleterow</button><br />
    <button value="3" onclick="deletecell()">deletecell</button><br />
    <hr />
    </body>

    </html>

  • 相关阅读:
    C#窗体 LISTVIEW
    C#窗体布局方式
    C#窗体计算器
    操作数据库(对战小游戏)
    C#窗体
    操作数据库(数据操作类)
    操作数据库(增删改)
    操作数据库(防注入攻击)
    DO.NET操作数据库
    projecteuler Problem 9 Special Pythagorean triplet
  • 原文地址:https://www.cnblogs.com/youcandomore/p/7251487.html
Copyright © 2011-2022 走看看