zoukankan      html  css  js  c++  java
  • [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>
     
  • 相关阅读:
    scratch资源
    如何把scratch转成一个swf文件或者exe执行文件
    perl的匿名引用
    perl的内置函数scalar
    perl内置特殊变量查询
    Win7中安装Windows PowerShell 3.0
    man-pages项目包含文档的说明
    编译器思维之结合律
    Android中利用jsoup解析html页面
    MVP+Retrofit+RxJava
  • 原文地址:https://www.cnblogs.com/lyggqm/p/5627566.html
Copyright © 2011-2022 走看看