當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


HTML TableHeader cellIndex用法及代碼示例

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


相關用法


注:本文由純淨天空篩選整理自ManasChhabra2大神的英文原創作品 HTML | DOM TableHeader cellIndex Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。