在表格中有单词“ CRITICAL”和“ SAFE”,我想计算一下表格中有多少CRITICAL。并且,请不要添加类名或ID名称。
<table>
<tr>
<td>CRTICAL</td>
<td>CRTICAL</td>
<td>CRTICAL</td>
<td>SAFE</td>
</tr>
<tr>
<td>SAFE</td>
<td>CRTICAL</td>
<td>CRTICAL</td>
<td>CRTICAL</td>
</tr>
</table>
答案 0 :(得分:1)
使用:包含在JS(jQuery)中
var test = $('td:contains(CRTICAL)');
console.log(test.size());
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<table>
<tr>
<td>CRTICAL</td>
<td>CRTICAL</td>
<td>CRTICAL</td>
<td>SAFE</td>
</tr>
<tr>
<td>SAFE</td>
<td>CRTICAL</td>
<td>CRTICAL</td>
<td>CRTICAL</td>
</tr>
</table>