Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2016-05-16 15:35:214552browse

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> 

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; 

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.

Statement:
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