HTML DOM Tabla createCaption método ()
Definición y Uso
createCaption método () se utiliza para conseguir una mesa o crear un elemento <caption>.
Nota: Si elelemento caption en la tabla ya existe, createCaption () devuelve el título existente, en lugar de crear uno nuevo <caption> elemento.
Consejo: Retire los elementos de texto de la tabla, utilice deleteCaption () método.
gramática
tableObject.createCaption()
Soporte para el navegador
Todos los principales navegadores soportan createCaption método ()
Ejemplos
Ejemplos
En el siguiente ejemplo se crea una mesa para el título:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
var x=document.getElementById("myTable").createCaption();
x.innerHTML="<b>我的表格标题</b>";
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
<tr>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">创建一个表格标题</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
var x=document.getElementById("myTable").createCaption();
x.innerHTML="<b>我的表格标题</b>";
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
<tr>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">创建一个表格标题</button>
</body>
</html>
Trate »
Tabla de objetos