HTML DOM中的TableHeader cellIndex屬性用於返回表格行的單元格集合中單元格的位置。
用法:
- 它返回cellIndex屬性:
tableheaderObject.cellIndex
返回值:它返回一個數字值,該值表示表行的單元格集合中單元格的位置。
例:
<!DOCTYPE html>
<html>
<head>
<!-- style to set border -->
<style>
table,
th,
td {
border:1px solid black;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>DOM TableHeader CellIndex Property</h2>
<table>
<tr>
<th id="gfg" onclick="myGeeks(this)">
Username
</th>
<th id="gfg" onclick="myGeeks(this)">
Id
</th>
</tr>
<tr>
<td>geeks</td>
<td>23456</td>
</tr>
</table>
<p>
Click on TableHeader to get the CellIndex th element.
</p>
<!-- Script to access th element -->
<script>
function myGeeks(x) {
alert("cell index is:" + x.cellIndex);
}
</script>
</body>
</html>
輸出:
在單擊“表格”單元格之前:
單擊“表格”單元格後:
支持的瀏覽器:下麵列出了DOM TableHeader cellIndex屬性支持的瀏覽器:
- 穀歌瀏覽器
- IE瀏覽器
- Firefox
- 蘋果Safari
- Opera
相關用法
- HTML TableData cellIndex用法及代碼示例
- HTML TableHeader abbr用法及代碼示例
- HTML DOM TableHeader用法及代碼示例
- HTML li value用法及代碼示例
- HTML DOM name用法及代碼示例
- HTML DOM URL用法及代碼示例
- HTML DOM id用法及代碼示例
- HTML Map name用法及代碼示例
- HTML DOM value用法及代碼示例
- HTML DOM dir用法及代碼示例
- HTML DOM specified用法及代碼示例
- HTML Bdo dir用法及代碼示例
- HTML DOM title用法及代碼示例
- HTML HR width用法及代碼示例
- HTML DOM isContentEditable用法及代碼示例
注:本文由純淨天空篩選整理自ManasChhabra2大神的英文原創作品 HTML | DOM TableHeader cellIndex Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。