tr deleteCell() 方法

定義和用法
deleteCell() 方法用於刪除表格行中的單元格(<td> 元素)。
語法
trObject.deleteCell(index)
值 | 描述 |
---|---|
index | 參數 index 是要刪除的表元在行中的位置。 該方法將刪除表行中指定位置的表元。 |
流覽器支持
所有主流流覽器都支持 deleteCell() 方法
實例
實例
下麵的例子從行中刪除了一個單元格:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function displayResult(){
var firstRow=document.getElementById("myTable").rows[0];
firstRow.deleteCell(0);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>First cell</td>
<td>Second cell</td>
<td>Third cell</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">刪除第一個單元格</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function displayResult(){
var firstRow=document.getElementById("myTable").rows[0];
firstRow.deleteCell(0);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>First cell</td>
<td>Second cell</td>
<td>Third cell</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">刪除第一個單元格</button>
</body>
</html>
