How can I use JavaScript to obtain the number of rows and columns in a table? In fact, it is very simple. Assume that the following table exists:
<table width="100%" border="1" cellspacing="0" cellpadding="0" id="example_table"> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr></table>
The following code retrieves the number of rows and columns of the table:
// Table row var rows = document. getElementById ("example_table "). rows. length; // Number of table columns var cells = document. getElementById ("example_table "). rows. item (0 ). cells. length;
Articles you may be interested in
- Js obtains the number of rows and columns of a table (compatible with IE and firefox)
- Jquery achieves the effect of table row-changing
- Js can only enter numbers and numbers with decimal points, compatible with IE and firefox
- Javascript restricts that only numbers (including decimal places) can be entered in the text box)
- Js restrictions: Only English letters and numbers can be entered. Chinese characters and other special characters cannot be entered.
- When CuteFTP is connected to the ftp server, the "invalid Parameters" error is displayed.
- How to obtain the complete url address and parameters in javascript
- Smarty loops the table and supplements the table with insufficient td Information