HTML DOM 中的 TableRow deleteCell() 方法用于从表格的当前行中删除单元格。它是 TableRow 对象的预定义方法。
用法:
tablerowObject.deleteCell(index)
属性值:
index:它包含一个从 0 开始的数值,它定义了要从当前行中删除的单元格的位置。例如 - 值 0th 表示要删除的第一个定位单元格。第 -1 个值表示删除最后一个定位的单元格。
注意:
- 该参数在 Firefox 和 Opera 浏览器中被定义为必填项。另一方面,它在 safari、chrome 和 IE 浏览器中是可选的。
- 如果此参数不包含任何值,则 deleteCell() 删除 IE 中的最后一个单元格以及 Chrome 和 Safari 中的第一个单元格。
例:在这个例子中,我们将从当前行中删除第一个和单元格。
HTML
<!DOCTYPE html>
<html>
<head>
<title>
HTML DOM TableRow deleteCell() Method
</title>
<style>
table,
td {
border:1px solid green;
}
h1 {
color:green;
}
h2 {
font-family:Impact;
}
body {
text-align:center;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>
HTML DOM TableRow deleteCell() Method
</h2>
<table align="center">
<tr id="gfg">
<td>GEEKS</td>
<td>FOR</td>
<td>GEEKS</td>
</tr>
</table>
<br>
<button onclick="firstCell()">
Delete the First Cell
</button>
<button onclick="lastCell()">
Delete the Last Cell
</button>
<script>
function firstCell() {
var Cell =
document.getElementById("gfg");
Cell.deleteCell(0);
}
function lastCell() {
var MyCell = document.getElementById("gfg");
MyCell.deleteCell(-1);
}
</script>
</body>
</html>
输出:
相关用法
- HTML TableRow rowIndex用法及代码示例
- HTML DOM TableRow sectionRowIndex属性用法及代码示例
- HTML TableRow align用法及代码示例
- HTML DOM TableRow用法及代码示例
- HTML DOM HTML用法及代码示例
- HTML DOM isEqualNode()用法及代码示例
- HTML DOM History go()用法及代码示例
- HTML Input Date stepUp()用法及代码示例
- HTML DOM console.warn()用法及代码示例
- HTML DOM console.clear()用法及代码示例
- HTML DOM blur()用法及代码示例
- HTML DOM createElement()用法及代码示例
- HTML DOM queueMicrotask()用法及代码示例
- HTML DOM Location replace()用法及代码示例
- HTML DOM close()用法及代码示例
- HTML DOM createAttribute()用法及代码示例
- HTML DOM writeln()用法及代码示例
- HTML DOM console.trace()用法及代码示例
- HTML DOM createComment()用法及代码示例
- HTML DOM console.table()用法及代码示例
- HTML DOM console.time()用法及代码示例
注:本文由纯净天空筛选整理自ManasChhabra2大神的英文原创作品 HTML DOM TableRow deleteCell() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。