计算HTML表格中的行数,但不计算< th>< / th>作为一排 [英] Counting the number of rows in an HTML table except don't count the <th></th> as a row
本文介绍了计算HTML表格中的行数,但不计算< th>< / th>作为一排的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要你的帮助,
如果下面的代码计算表中的每一个表行,如何修改它以使代码不计入< th>< / th>
作为一行本身?
if the following code below counts every table row in a table, how can it be amended such that the code won't count the <th></th>
as a row itself?
var rows = document.getElementById("data").rows.length;
推荐答案
你应该使用thead和tbody
You should be using thead and tbody
HTML:
<table id="data">
<thead>
<tr><th>Hz</th></tr>
</thead>
<tbody>
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>3</td></tr>
</tbody>
</table>
JavaScript:
JavaScript:
var rows = document.getElementById("data").getElementsByTagName("tbody")[0].rows.length;
这篇关于计算HTML表格中的行数,但不计算< th>< / th>作为一排的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文