增加删除行

2016-02-22    编辑:kp12345     点击(

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Table test</title>


</head>
<body>
<table id="table1" bordercolor="#000000" width="200" border="1">
    <tbody>
        <tr>
            <td>00</td>
            <td>01</td>
            <td>02</td>
            <td>03</td>
        </tr>
        <tr>
            <td>10</td>
            <td>11</td>
            <td>12</td>
            <td>13</td>
        </tr>
        <tr>
            <td>20</td>
            <td>21</td>
            <td>22</td>
            <td>23</td>
        </tr>
        <tr>
            <td>30</td>
            <td>31</td>
            <td>32</td>
            <td>33</td>
        </tr>
        <tr>
            <td>40</td>
            <td>41</td>
            <td>42</td>
            <td>43</td>
        </tr>
    </tbody>
</table>
<br/>
<input type="button" value="删除一行" onclick="deleteRow()"/>&nbsp; &nbsp;
<input type="button" value="删除一列" onclick="deleteColumn()"/>
</body>
</html>
<script language="JavaScript" type="text/javascript">
<!--
//获得表格对象
var _table=document.getElementById("table1");

//定义函数,用于删除第一行
function deleteRow(){
 _table.deleteRow(0);
}
//定义函数,用于删除第一列
function deleteColumn(){
 //删除一列时需要对每一行分别进行列删除
 for(var i=0;i<_table.rows.length;i++){
  _table.rows[i].deleteCell(0);
 }
}
//-->
</script>