获取表格的行数和列数
html:
<body> <table id="tab"> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> </table> <table id="tt"> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>3</td> <td>4</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>3</td> <td>4</td> </tr> </table> </body>
js:
function show(el){ var oEl = document.getElementById(el); var rows = oEl.rows.length; var cells = oEl.rows.item(0).cells.length; console.log(rows,cells) } show('tab') show('tt')