Dieser Inhalt wurde automatisch aus dem Englischen übersetzt, und kann Fehler enthalten. Erfahre mehr über dieses Experiment.
HTMLTableCellElement: cellIndex-Eigenschaft
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since Juli 2015.
Die cellIndex schreibgeschützte Eigenschaft des HTMLTableCellElement Schnittstelle
repräsentiert die Position einer Zelle innerhalb ihrer Zeile (<tr>). Die erste Zelle hat einen Index von 0.
Wert
Gibt den Index der Zelle zurück oder -1, wenn die Zelle nicht Teil einer Zeile ist.
Beispiele
Dieses Beispiel fügt allen Zellnummern der ersten Zeile des tbody ein Label hinzu.
HTML
html
<table>
<thead>
<tr>
<th>Item</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bananas</td>
<td>2ドル</td>
</tr>
<tr>
<td>Rice</td>
<td>2ドル.5</td>
</tr>
</tbody>
</table>
table {
border-collapse: collapse;
}
th,
td,
table {
border: 1px solid black;
}
button {
margin: 1em 1em 1em 0;
}
JavaScript
js
const rows = document.querySelectorAll("tbody tr");
const cells = rows[0].cells;
for (const cell of cells) {
cell.textContent = `${cell.textContent} (cell #${cell.cellIndex})`;
}
Ergebnis
[フレーム]
Spezifikationen
| Specification |
|---|
| HTML> # dom-tdth-cellindex> |
Browser-Kompatibilität
Enable JavaScript to view this browser compatibility table.