HTMLTableCellElement: colSpan ããããã£
Baseline
åºãå©ç¨å¯è½
ãã®æ©è½ã¯åºãå®è£ ããã¦ãããå¤ãã®ãã¼ã¸ã§ã³ã®ç«¯æ«ããã©ã¦ã¶ã¼ã§åä½ãã¾ãã2015å¹´7æä»¥éããã¹ã¦ã®ãã©ã¦ã¶ã¼ã§å©ç¨å¯è½ã§ãã
colSpan 㯠HTMLTableCellElement ã¤ã³ã¿ã¼ãã§ã¤ã¹ã®ããããã£ã§ããã®ã»ã«ãã¾ãããåã®æ°ã表ãã¾ããããã«ãããã»ã«ã¯è¡¨ã®è¤æ°ã®åã«ã¾ããã£ã¦ç©ºéãå ãããã¨ãã§ããããã«ãªãã¾ãããã㯠colspan 屿§ã«å¯¾å¿ãã¦ãã¾ãã
å¤
åã®æ°ãè¡¨ãæ£ã®æ°å¤ã§ãã
ã¡ã¢: æ°ããå¤ãè¨å®ããéããã®å¤ã¯æãè¿ãæ£ã®æ°å¤ã«ä¸¸ãããã¾ãã
ä¾
ãã®ä¾ã§ã¯ãæ¬æã®æåã®ã»ã«ãã¾ãããåã®æ°ã夿´ããããã® 2 ã¤ã®ãã¿ã³ãæä¾ããã¦ãã¾ãã
HTML
<table>
<thead>
<tr>
<th>å 1</th>
<th>å 2</th>
<th>å 3</th>
<th>å 4</th>
<th>å 5</th>
<th>å 6</th>
<th>å 7</th>
<th>å 8</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2">1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
</tr>
</tbody>
</table>
<button id="increase">colspan ãå¢ãã</button>
<button id="decrease">colspan ãæ¸ãã</button>
<div>æåã®ã»ã«ã¯ <output>2</output> åã«ã¾ãããã¾ãã</div>
JavaScript
// è¦ç´ ã«é¢é£ããã¤ã³ã¿ã¼ãã§ã¤ã¹ãåå¾ãã
const cell = document.querySelectorAll("tbody tr td")[0];
const output = document.querySelectorAll("output")[0];
const increaseButton = document.getElementById("increase");
const decreaseButton = document.getElementById("decrease");
increaseButton.addEventListener("click", () => {
cell.colSpan += 1;
// è¡¨ç¤ºãæ´æ°
output.textContent = cell.colSpan;
});
decreaseButton.addEventListener("click", () => {
cell.colSpan -= 1;
// è¡¨ç¤ºãæ´æ°
output.textContent = cell.colSpan;
});
çµæ
仿§æ¸
| 仿§æ¸ |
|---|
| HTML > # dom-tdth-colspan > |