如何使用jQuery过滤表中的数值?

时间:2018-01-14 00:31:02

标签: jquery

如果第3列中的数据高于或等于100,我试图突出显示黄色表的行,如果它低于20,则删除该行。表格看起来像这样:



<table>
    <tr>
        <th>Animal</th>
        <th>Color</th>
        <th>Quantity</th>
    </tr>
    <tr>
        <td>Cat</td>
        <td>Purple</td>
        <td>17</td>
    </tr>
    <tr>
        <td>Dog</td>
        <td>Orange</td>
        <td>236</td>
    </tr>
    … etc.
</table>
&#13;
&#13;
&#13;

这是我到目前为止所做的,但似乎并没有起作用:

&#13;
&#13;
$("table tr td:nth-child(3)").filter(function() {
   return (this.text() >= 100);}).parent().css("background", "yellow");
&#13;
&#13;
&#13;

我想我错过了一些语法,但我不确定如何修复它。感谢您提前提供任何帮助。

1 个答案:

答案 0 :(得分:0)

只需将文字更改为innerText

即可
$("table tr td:nth-child(3)").filter(function() {
    return (this.innerText >= 100);}).parent().css("background", "yellow");