少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

          <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
          <title>javascript實現表格動態增加刪除</title>

          <script>
           function addline() {
            var tb = document.getElementById("mytable");
            var row = tb.insertRow(tb.rows.length);
            var colname = row.insertCell(row.cells.length);
            var colage = row.insertCell(row.cells.length);
            var colbutton = row.insertCell(row.cells.length);

            colname.innerHTML = document.getElementById("name1").value;
            colage.innerHTML = document.getElementById("age1").value;
            colbutton.innerHTML = '<input type="button" value="刪除" onclick="deleteRow('
              + (tb.rows.length - 1) + ')" />'
           }
           function deleteRow(index) {
            var tb = document.getElementById("mytable");
            tb.deleteRow(index);
           }
          </script>
          <body>
           <table id="mytable" border="1">
            <tr>
             <td>NAME</td>
             <td>AGE</td>
             <td>OPERATE</td>
            </tr>
           </table>
           <input type="text" name="name" id="name1" />
           <input type="text" name="age" id="age1" />
           <input type="button" value="PRESS" onclick="return addline();" />
          </body>
          </html>

          主站蜘蛛池模板: 华池县| 怀宁县| 邢台县| 台北县| 四川省| 剑阁县| 安乡县| 保德县| 平顺县| 沙雅县| 河间市| 双柏县| 库伦旗| 襄垣县| 太谷县| 岱山县| 济阳县| 东乡县| 聊城市| 衡东县| 武义县| 丹东市| 印江| 夹江县| 孟津县| 龙口市| 诸城市| 津南区| 房产| 金昌市| 南雄市| 涡阳县| 星座| 玉山县| 阿图什市| 台南县| 日照市| 忻城县| 区。| 井陉县| 新巴尔虎右旗|