JS获取表格行数和列数

<html>
<head>
<script type="text/javascript">
function show()
{
var tab = document.getElementById("test") ;
//表格行数
var rows = tab.rows.length ;
//表格列数
var cells = tab.rows.item(0).cells.length ;
alert("行数"+rows+"列数"+cells);
}
</script>
</head>
<body>
<table id="test" border="1">
<tr>
<td>&nbsp;</td><td>nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td><td>nbsp;</td>
</tr>
</table>
<input type="button" onclick="show();"/>
</body>
</html>

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/courses/259267.html

(0)
上一篇 2022年5月21日 16:16
下一篇 2022年5月21日 16:21

相关推荐

发表回复

登录后才能评论