少年阿賓

          那些青春的歲月

            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>

          主站蜘蛛池模板: 四川省| 涿州市| 凤城市| 茂名市| 九龙城区| 阳曲县| 昆明市| 鄂尔多斯市| 香港| 五大连池市| 沾益县| 化隆| 积石山| 梨树县| 武义县| 潮安县| 潞西市| 乡城县| 灵山县| 揭东县| 上高县| 永春县| 彰武县| 拉萨市| 且末县| 揭东县| 满洲里市| 绥德县| 竹溪县| 满城县| 威信县| 榆社县| 平武县| 静乐县| 平远县| 林周县| 武乡县| 巢湖市| 宜城市| 博白县| 桂阳县|