JavaScript 获取表格的行数和列数
<html>
<head>
<title>JS获取表格行数和列数</title>
<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" style="width:400px;">
<tr>
<td width="50%">张三</td>
<td width="35%">男</td>
</tr>
<tr>
<td>李敏</td>
<td>女</td>
</tr>
</table>
<table id="test" border="0" style="margin-top:10px;">
<input type="button" value="获取表格行数、列数" οnclick="show();"/>
</table>
</body>
</html>