Home > Web Front-end > JS Tutorial > js method to get the number of rows and columns of a table_javascript skills

js method to get the number of rows and columns of a table_javascript skills

WBOY
Release: 2016-05-16 15:35:21
Original
4579 people have browsed it

How to use JavaScript to get the number of rows and columns of a table? It’s actually very simple, assuming 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> 
Copy after login

The following codes can be used to obtain the number of rows and columns of the table:

//表格行数 
var rows = document.getElementById("example_table").rows.length; 
 
//表格列数 
var cells = document.getElementById("example_table").rows.item(0).cells.length; 
Copy after login

You can use the above code to easily obtain the row number and column of the table through JavaScript. I hope this article will be helpful to your study.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template