Baseline Widely available
HTMLTableRowElement
æ¥å£ç deleteCell()
æ¹æ³ä»ç»å®ç <tr>
ä¸ç§»é¤ç¹å®çè¡åå
æ ¼ã
index
è¦ç§»é¤åå
æ ¼çåå
æ ¼ç´¢å¼ã妿 index
弿¯ -1
æè
çäºåå
æ ¼çæ°éï¼åç§»é¤è¡çæåä¸ä¸ªåå
æ ¼ã
æ ï¼undefined
ï¼ã
IndexSizeError
DOMException
妿 index
大äºåå
æ ¼æ°æå°äº -1
ï¼åæåºè¯¥å¼å¸¸ã
æ¤ç¤ºä¾ä½¿ç¨ HTMLTableRowElement.insertCell()
å°æ°çåå
æ ¼éå å°è¡ä¸ã
<table>
<thead>
<tr>
<th>C1</th>
<th>C2</th>
<th>C3</th>
<th>C4</th>
<th>C5</th>
</tr>
</thead>
<tbody>
<tr>
<td>åå
æ ¼ 1</td>
<td>åå
æ ¼ 2</td>
</tr>
</tbody>
</table>
<button id="add">æ·»å åå
æ ¼</button>
<button id="remove">ç§»é¤æåçåå
æ ¼</button>
<div>第ä¸è¡æ <output>2</output> 个åå
æ ¼ã</div>
table {
border-collapse: collapse;
}
th,
td,
table {
border: 1px solid black;
}
button {
margin: 1em 1em 1em 0;
}
JavaScript
// è·åç¸å
³æ¥å£å
ç´
const bodySection = document.querySelectorAll("tbody")[0];
const row = bodySection.rows[0]; // éæ©è¡¨æ ¼ä½é¨åç第ä¸è¡
const cells = row.cells; // é忝卿çï¼å æ¤æ»æ¯ææ°ç
const cellNumberDisplay = document.querySelectorAll("output")[0];
const addButton = document.getElementById("add");
const removeButton = document.getElementById("remove");
function updateCellNumber() {
cellNumberDisplay.textContent = cells.length;
}
addButton.addEventListener("click", () => {
// å¨ç¬¬ä¸è¡çæ«å°¾æ·»å åå
æ ¼
const newCell = row.insertCell();
newCell.textContent = `åå
æ ¼ ${cells.length}`;
// æ´æ°è¡æ°
updateCellNumber();
});
removeButton.addEventListener("click", () => {
// ä»è¡¨æ ¼ä½å é¤è¡
row.deleteCell(-1);
// æ´æ°è¡æ°
updateCellNumber();
});
ç»æ è§è æµè§å¨å
¼å®¹æ§ åè§
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