我试图做一个简单的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>
Run Code Online (Sandbox Code Playgroud)
js / jquery:
var rowCount = $("#offices > tr").length;
alert(rowCount);
var i = 0;
while ( ++i <= rowCount ) {
console.log( "counting rows: " + i );
}
Run Code Online (Sandbox Code Playgroud)