且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用jquery计算表中的行数

更新时间:2023-02-06 11:00:30

试试这个:

var rows = document.getElementById('myTableId').getElementsByTagName('tbody')[0].getElementsByTagName('tr').length;

http:// jsfiddle.net/y8URn/

它会计算< tr> 的数量< tbody> ,这又是表格中的行数。

It will count the number of <tr>s in the <tbody>, which in turn will be the number of rows in the table.

请注意它不会仅计算表格表格中的所有行。如果您有一个< thead> 或一个< tfoot> ,或者甚至是tbody之外的一行,那么不计算在内。

Do note that it will NOT count all of the rows in the table only in the table body. If you have a <thead> or a <tfoot> or even a row outside of the tbody, it will not be counted.