Baseline Widely available
Die rowSpan
-Eigenschaft des HTMLTableCellElement
-Interfaces ist eine schreibgeschützte Eigenschaft, die die Anzahl der Zeilen darstellt, die diese Zelle überspannen muss; dies ermöglicht es der Zelle, Platz über mehrere Zeilen der Tabelle hinweg einzunehmen. Sie entspricht dem rowspan
-Attribut.
Eine positive Zahl, die die Anzahl der Zeilen darstellt. Wenn sie 0
ist, bedeutet dies alle verbleibenden Zeilen in der Spalte.
Hinweis: Beim Setzen eines neuen Wertes wird ein von 0 abweichender Wert auf die nächstgelegene strikt positive Zahl geklammert.
BeispieleDieses Beispiel bietet zwei Buttons, um die Zeilenspanne der ersten Zelle des Körpers zu ändern.
HTML<table>
<thead>
<tr>
<th>Col 1</th>
<th>Col 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td rowspan="2">2</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>4</td>
</tr>
</tbody>
</table>
<button id="increase">Increase rowspan</button>
<button id="decrease">Decrease rowspan</button>
<div>The second cell of the first column spans <output>2</output> row(s).</div>
table {
border-collapse: collapse;
}
th,
td,
table {
border: 1px solid black;
}
button {
margin: 1em 1em 1em 0;
}
JavaScript
// Obtain relevant interface elements
const row = document.querySelectorAll("tbody tr")[1];
const cell = row.cells[0];
const output = document.querySelectorAll("output")[0];
const increaseButton = document.getElementById("increase");
const decreaseButton = document.getElementById("decrease");
increaseButton.addEventListener("click", () => {
cell.rowSpan += 1;
// Update the display
output.textContent = cell.rowSpan;
});
decreaseButton.addEventListener("click", () => {
cell.rowSpan -= 1;
// Update the display
output.textContent = `${cell.rowSpan === 0 ? "all remaining" : cell.rowSpan}`;
});
Ergebnis Spezifikationen Browser-Kompatibilität Siehe auch MDN-Feedback-Box War diese Ãbersetzung hilfreich?
Diese Seite wurde automatisch aus dem Englischen übersetzt.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4