Latest web development tutorials

HTML DOM tr deleteCell () metode

tr Referensi Obyek benda tr

Definisi dan Penggunaan

Metode deleteCell () digunakan untuk menghapus baris dalam sel tabel (<td> elemen).

tatabahasa

trObject.deleteCell(index)

描述
index

参数 index 是要删除的表元在行中的位置。

该方法将删除表行中指定位置的表元。



Dukungan Browser

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Semua browser utama mendukung deleteCell () metode


contoh

contoh

Contoh berikut menghapus sel dari garis:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.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>

Coba »


tr Referensi Obyek benda tr