td/th headers属性

td/th 对象参考手册td/th オブジェクト

定義と使い方

headers 属性は、現在のデータセルがヘッダー情報を含むヘッダーのリストを設定または返します。

この属性の値は、引用符で囲まれた名前のリストであり、これらの名前は id 属性で定義された異なるヘッダーセルの名前です。

構文

headers 属性を設定する:

tdObject.headers="header_ids"

or

thObject.headers="header_ids"

headers 属性を返す:

tdObject.headers

or

thObject.headers

ヒント:headers 属性にデフォルト値はありません。

值 説明
header_ids スペース区切りのヘッダーセルIDリストを定義します。


ブラウザサポート

Internet ExplorerFirefoxOperaGoogle ChromeSafari

すべての主要ブラウザは headers 属性に対応しています。


例

例

2行目のヘッダーを表示:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル(example.com)</title>
<script>
function displayResult(){
    var table=document.getElementById("myTable");
    for (var i=0;i<table.rows[1].cells.length;i++){
        alert(table.rows[1].cells[i].headers);
    }
}
</script>
</head>
<body>

<table id="myTable" border="1" width="100%">
    <tr>
<th id="name">名前</th>
        <th id="email">Email</th>
<th id="phone">電話</th>
<th id="addr">住所</th>
    </tr>
    <tr>
        <td headers="name">John Doe</td>
        <td headers="email">[email protected]</td>
        <td headers="phone">+45342323</td>
        <td headers="addr">Rosevn 56,4300 Sandnes,Norway</td>
    </tr>
</table>
<br>
<button type="button" onclick="displayResult()">2行目のセルヘッダーを取得</button>

</body>
</html>

試してみる »


td/th 对象参考手册td/th オブジェクト その他の拡張