我有下表:
<table>
<tr>
<th>Alarm</th>
</tr>
<tr>
<td>OK</td>
</tr>
<tr>
<td>Missing</td>
</tr>
<tr>
<td>OK</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
我想像这样计算这个表中的行
OK = 2
Missing = 1
但我不知道如何使用jQuery,选择器应该只为警报列指定,因为我有其他列包含确定和缺少
注意:我想计算表中特定列的行,仅用于报警列,alaram列包含2个ok和1个缺失.
假设Alarm是第一列:
var okCount = $('td:contains("OK")').filter(function() {
return $(this).index() == 0;
}).length;
var missingCount = $('td:contains("Missing")').filter(function() {
return $(this).index() == 0;
}).length;
console.log('okCount: ' + okCount);
console.log('missingCount : ' + missingCount);?
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2661 次 |
| 最近记录: |