• [HTML]HTML5实现可编辑表格


    HTML5实现的简单的可编辑表格

    [HTML]代码

    <!DOCTYPE html >
    <html >
    <head>
    <meta charset="utf-8" />
    <title>可编辑表格</title>
    <script>
    function addRow(){
        var oTable = document.getElementById("oTable");
        var tBodies = oTable.tBodies;
        var tbody = tBodies[0];
        var tr = tbody.insertRow(tbody.rows.length);
        var td_1 = tr.insertCell(0);
        td_1.innerHTML = "<div contenteditable='true'>第1列</div>";
        var td_2 = tr.insertCell(1);
        td_2.innerHTML = "<div contenteditable='true'>第2列</div>";
        }
    
    </script>
    </head>
    <body>
    <fieldset>
    <legend>可编辑的表格</legend>
    <table id="oTable" style="background-color:#eeeeee;" bordercolor="#aaaaaa" border="1" cellpadding="0" cellpadding="2" width="100%">
    <thead>
    <tr>
    <th>第一列标题</th>
    <th>第二列标题</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td><div contenteditable="true">第一行第一列</div></td>
    <td><div contenteditable="true">第一行第二列</div></td>
    </tr>
    </tbody>
    </table>
    </fieldset>
    <input type="button" onClick="addRow();" style="font-size:16px;" value="+"/>
    </body>
    </html>

    [HTML]代码

    <!DOCTYPE html >
    <html >
    <head>
    <meta charset="utf-8" />
    <title>可编辑表格</title>
    <script>
    function addRow(){
        var oTable = document.getElementById("oTable");
        var tBodies = oTable.tBodies;
        var tbody = tBodies[0];
        var tr = tbody.insertRow(tbody.rows.length);
        var td_1 = tr.insertCell(0);
        td_1.innerHTML = "<div contenteditable='true'>第1列</div>";
        var td_2 = tr.insertCell(1);
        td_2.innerHTML = "<div contenteditable='true'>第2列</div>";
        }
    
    </script>
    </head>
    <body>
    <fieldset>
    <legend>可编辑的表格</legend>
    <table id="oTable" style="background-color:#eeeeee;" bordercolor="#aaaaaa" border="1" cellpadding="0" cellpadding="2" width="100%">
    <thead>
    <tr>
    <th>第一列标题</th>
    <th>第二列标题</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td><div contenteditable="true">第一行第一列</div></td>
    <td><div contenteditable="true">第一行第二列</div></td>
    </tr>
    </tbody>
    </table>
    </fieldset>
    <input type="button" onClick="addRow();" style="font-size:16px;" value="+"/>
    </body>
    </html>
     
  • 相关阅读:
    react特点和创建虚拟DOM
    vue的keep-alive
    JavaScript-事件委托
    vue-router参数传递
    js常用的字符串处理
    vue-vuex
    vue-组件
    vue-父子组件传值
    堆和栈
    js-深拷贝浅拷贝
  • 原文地址:https://www.cnblogs.com/lyggqm/p/5627566.html
Copyright © 2020-2023  润新知