<table>
<tr>
<th>表頭</th>
<td>資料</td>
</tr>
</table>
<tr> (Table Row) 僅能作為 <table>、<thead>、<tbody>、<tfoot> 的直接子元素,包含一或多個 <th> 或 <td>。
| 屬性 | 說明 | 值 | 狀態 |
|---|---|---|---|
| align | 水平對齊 | left | center | right | justify | char | 棄用 (CSS: text-align) |
| valign | 垂直對齊 | top | middle | bottom | baseline | 棄用 (CSS: vertical-align) |
| bgcolor | 背景色 | 顏色值 | 棄用 (CSS: background-color) |
| char | 對齊字元 (配合 align=char) | 單字元 | 棄用 |
| charoff | 字元偏移量 | 長度 | 棄用 |
| 全域屬性 | id, class, style, data-*, aria-*, tabindex 等 | -- | 支援 |
| 事件屬性 | onclick, onmouseover 等 | -- | 支援 (建議用 addEventListener) |
<style>
tr:nth-child(even) { background: #f9f9f9; } /* 斑馬紋 */
tr:hover { background: #eef; } /* 懸停高亮 */
tr.selected { background: #bde; } /* 選中狀態 */
td, th { text-align: left; vertical-align: middle; padding: 8px 12px; }
/* 邏輯屬性支援 RTL */
td { text-align: start; }
</style>
<th scope="col|row"> 明確表頭範圍<caption> 提供表格標題/摘要<thead>/<tbody>/<tfoot> 結構化rowspan/colspan 需在 <td>/<th> 上設定table.rows 可能包含 thead/tfoot 行const row = table.insertRow(index); // 插入行 (自動建立 td 需手動)
row.insertCell(index); // 插入儲存格
row.deleteCell(index);
row.cells; // HTMLCollection of cells
row.rowIndex; // 在整個 table 中的索引
row.sectionRowIndex; // 在 thead/tbody/tfoot 中的索引