TamperMonkey - 如果列不包含,则删除表行

时间:2017-06-07 14:55:25

标签: javascript jquery html html-table tampermonkey

有一个我用于工作的网站(仍使用表格),其中包含表格中的多个行。我想删除此表中第二列中不包含“KEEP ME”的行。正如你在下面的代码片段中看到的那样,问题是内容不仅仅在TD中,而且它们包含在NOBR中,然后包含在TD中的SPAN中。

<table id="T536870939" title="" class="BaseTable" style="width: 1879px;">
    <tbody>
        <tr tabindex="0" style=" color:#808000;" arrow="0">
            <td style="width: 155px;" class="BaseTableCellOdd BaseTableCellOddColor BaseTableStaticText">
                <nobr class="dp " style="text-align: left; width: 155px;">
                    <span style="padding: 1px 4px;float:left;">Who cares?</span>
                </nobr>
            </td>
            <td style="width: 89px;" class="BaseTableCellOdd BaseTableCellOddColor BaseTableStaticText">
                <nobr class="dp " style="text-align: left; width: 89px;">
                    <span style="padding: 1px 4px;float:left;">KEEP ME</span>
                </nobr>
            </td>
            <td style="width: 155px;" class="BaseTableCellOdd BaseTableCellOddColor BaseTableStaticText">
                <nobr class="dp " style="text-align: left; width: 155px;">
                    <span style="padding: 1px 4px;float:left;">Who cares?</span>
                </nobr>
            </td>
        </tr>
        <tr tabindex="0" style=" color:#808000;" arrow="1">
            <td style="width: 155px;" class="BaseTableCell BaseTableCellOddColor BaseTableStaticText">
                <nobr class="dp " style="text-align: left; width: 155px;">
                    <span style="padding: 1px 4px;float:left;">Who cares?</span>
                </nobr>
            </td>
            <td style="width: 89px;" class="BaseTableCell BaseTableCellOddColor BaseTableStaticText">
                <nobr class="dp " style="text-align: left; width: 89px;">
                    <span style="padding: 1px 4px;float:left;">I'M BAD! DELETE ME!</span>
                </nobr>
            </td>
            <td style="width: 155px;" class="BaseTableCell BaseTableCellOddColor BaseTableStaticText">
                <nobr class="dp " style="text-align: left; width: 155px;">
                    <span style="padding: 1px 4px;float:left;">Who cares?</span>
                </nobr>
            </td>
        </tr>
        <tr tabindex="0" style=" color:#808000;" arrow="2">
            <td style="width: 155px;" class="BaseTableCellOdd BaseTableCellOddColor BaseTableStaticText">
                <nobr class="dp " style="text-align: left; width: 155px;">
                    <span style="padding: 1px 4px;float:left;">Who cares?</span>
                </nobr>
            </td>
            <td style="width: 89px;" class="BaseTableCellOdd BaseTableCellOddColor BaseTableStaticText">
                <nobr class="dp " style="text-align: left; width: 89px;">
                    <span style="padding: 1px 4px;float:left;">I'M ALSO BAD! PLEASE DELETE ME!</span>
                </nobr>
            </td>
            <td style="width: 155px;" class="BaseTableCellOdd BaseTableCellOddColor BaseTableStaticText">
                <nobr class="dp " style="text-align: left; width: 155px;">
                    <span style="padding: 1px 4px;float:left;">Who cares?</span>
                </nobr>
            </td>
        </tr>
    </tbody>
</table>

我尝试过使用下面的脚本,但是我没有成功。我做错了什么?

$('#T536870939 tr span:not([title!="KEEP ME"]):first').remove ();

0 个答案:

没有答案