我是一个有用的助手,可以为您进行文本翻译。
我正在尝试制作一个简单的while循环来计算表格#offices中行的数量,但是我不知道为什么这不起作用,而警报一直返回0...
html:
我正在尝试制作一个简单的while循环来计算表格#offices中行的数量,但是我不知道为什么这不起作用,而警报一直返回0...
html:
<table id="offices" class="table table-striped">
<caption class="text-left">
<p class="lead">Current List of Offices</p>
</caption>
<thead>
<tr>
<th>Office Name</th>
<th>Office abrev.</th>
<th>Display Order</th>
<th>Edit</th>
<!-- TMPL_UNLESS is_agent -->
<th>Delete</th>
<!-- /TMPL_UNLESS -->
</tr>
</thead>
<tbody>
<!-- TMPL_LOOP Office_loop -->
<tr>
<td><!-- TMPL_VAR office_name --></td>
<td><!-- TMPL_VAR short_name --></td>
<td><!-- TMPL_VAR sequence_number ESCAPE=0 --></td>
<td><a href="/office/edit/<!-- TMPL_VAR office_id -->"><i class="fa fa-edit"></i> Edit Office</a></td>
<!-- TMPL_UNLESS is_agent GLOBAL=1 -->
<td><a href="/office/delete/<!-- TMPL_VAR office_id -->"><i class="fa fa-trash-o"></i> Delete Office</a></td>
<!-- /TMPL_UNLESS -->
</tr>
<!-- /TMPL_LOOP -->
</tbody>
</table>
js/jquery:
var rowCount = $("#offices > tr").length;
alert(rowCount);
var i = 0;
while ( ++i <= rowCount ) {
console.log( "counting rows: " + i );
}
$("#offices tr")
。 - Satpal$("#offices > tbody > tr")
。 - Satpal