HTMLTableCellElement: rowSpan ããããã£
Baseline
åºãå©ç¨å¯è½
ãã®æ©è½ã¯åºãå®è£ ããã¦ãããå¤ãã®ãã¼ã¸ã§ã³ã®ç«¯æ«ããã©ã¦ã¶ã¼ã§åä½ãã¾ãã2015å¹´7æä»¥éããã¹ã¦ã®ãã©ã¦ã¶ã¼ã§å©ç¨å¯è½ã§ãã
rowSpan 㯠HTMLTableCellElement ã¤ã³ã¿ã¼ãã§ã¤ã¹ã®ããããã£ã§ããã®ã»ã«ãã¾ãããè¡ã®æ°ã表ãã¾ããããã«ãããã»ã«ã¯è¡¨ã®è¤æ°ã®è¡ã«ã¾ããã£ã¦ç©ºéãå ãããã¨ãã§ããããã«ãªãã¾ãããã㯠rowspan 屿§ã«å¯¾å¿ãã¦ãã¾ãã
å¤
è¡ã®æ°ãè¡¨ãæ£ã®å¤ã0ã®å ´åã¯ããã®åã®æ®ããã¹ã¦ã®è¡ã§ãã
ã¡ã¢: æ°ããå¤ãè¨å®ããéã0 以å¤ã®å¤ã¯ãæãè¿ãæ£ã®æ°å¤ã«ä¸¸ãããã¾ãã
ä¾
ãã®ä¾ã§ã¯ãæ¬æã®æåã®ã»ã«ãã¾ãããè¡ã®æ°ã夿´ããããã® 2 ã¤ã®ãã¿ã³ãæä¾ããã¦ãã¾ãã
HTML
<table>
<thead>
<tr>
<th>å 1</th>
<th>å 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">rowspan ãå¢ãã</button>
<button id="decrease">rowspan ãæ¸ãã</button>
<div>1 åç®ã® 2 ã¤ç®ã®ã»ã«ã¯ <output>2</output> è¡ã«ã¾ãããã¾ãã</div>
JavaScript
// è¦ç´ ã«é¢é£ããã¤ã³ã¿ã¼ãã§ã¤ã¹ãåå¾ãã
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;
// è¡¨ç¤ºãæ´æ°
output.textContent = cell.rowSpan;
});
decreaseButton.addEventListener("click", () => {
cell.rowSpan -= 1;
// è¡¨ç¤ºãæ´æ°
output.textContent = `${cell.rowSpan === 0 ? "all remaining" : cell.rowSpan}`;
});
çµæ
仿§æ¸
| 仿§æ¸ |
|---|
| HTML > # dom-tdth-rowspan > |