td/th headersPropiedad
Objeto td/th
Definición y uso
La propiedad headers establece o devuelve la lista de encabezados que contienen información de encabezado para la celda de datos actual.
El valor de esta propiedad es una lista de nombres entre comillas, que son los nombres de las diferentes celdas de encabezado definidas mediante el atributo id.
Sintaxis
Establecer la propiedad headers:
tdObject.headers="header_ids"
or
thObject.headers="header_ids"
or
thObject.headers="header_ids"
Devolver la propiedad headers:
tdObject.headers
or
thObject.headers
or
thObject.headers
Consejo:La propiedad headers no tiene un valor predeterminado.
| Valor | Descripción |
|---|---|
| header_ids | Define una lista de ids de celdas de encabezado separados por espacios. |
Compatibilidad con navegadores
![]()
![]()
![]()
![]()
![]()
Todos los navegadores principales son compatibles con la propiedad headers.
Ejemplo
Ejemplo
Mostrar el encabezado de la segunda fila:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de Ejemplo (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">Nombre</th>
<th id="email">Email</th>
<th id="phone">Teléfono</th>
<th id="addr">Dirección</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()">Obtener el encabezado de celda de la segunda fila</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de Ejemplo (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">Nombre</th>
<th id="email">Email</th>
<th id="phone">Teléfono</th>
<th id="addr">Dirección</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()">Obtener el encabezado de celda de la segunda fila</button>
</body>
</html>
Pruébalo »
Objeto td/th Otras extensiones