Maison  >  Article  >  interface Web  >  JS实现为表格动态添加标题的方法_javascript技巧

JS实现为表格动态添加标题的方法_javascript技巧

WBOY
WBOYoriginal
2016-05-16 16:06:531312parcourir

本文实例讲述了JS实现为表格动态添加标题的方法。分享给大家供大家参考。具体如下:

JS中的表格对象带有一个createCaption方法用于为表格创建标题caption

<!DOCTYPE html>
<html>
<head>
<script>
function createCaption()
{
var x=document.getElementById('myTable').createCaption();
x.innerHTML="My table caption";
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>Row1 cell1</td>
<td>Row1 cell2</td>
</tr>
<tr>
<td>Row2 cell1</td>
<td>Row2 cell2</td>
</tr>
</table>
<br>
<input type="button" onclick="createCaption()"
value="Create caption">
</body>
</html>

希望本文所述对大家的javascript程序设计有所帮助。

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn