查找文本并将其删除 jquery

Find text and remove it jquery

本文关键字:删除 jquery 文本 查找      更新时间:2023-09-26

可能的重复项:
使用 jQuery 查找文本字符串?

你如何找到一个文本字符串并使用jquery隐藏它。

<div class="report-box">
  <div class="title">test</div>
  <table>
    <tbody>
      <tr align="center" class="CellLabel">
        <td colspan="2">Day at a Glance</td>
      </tr>
      <tr class="CellLabel">
        <td>New Clients</td>
        <td>00000</td>
      </tr>
      <tr class="CellLabel">
      <  td>Money Received</td>
        <td>$ 0000,000.0000</td>
      </tr>
      <tr class="CellLabel">
        <td>Overdue Invoices</td>
        <td>0000000</td>
      </tr>
      <tr class="CellLabel">
        <td>Services</td>
        <td>000000</td>
      </tr>
      <tr align="right" class="CellLabel">
        <td colspan="2"></td>
      </tr>
    </tbody>
  </table>
</div>

我将如何删除

<tr class="CellLabel">
  <td>Money Received</td>
  <td>$ 0000,000.0000</td>
</tr>

从代码中使用 jQuery。

首先,你的html有点混乱,缺少一些标签。但是你去吧。;)

1:

预览 - http://jsfiddle.net/Xpc63/1/

$('.CellLabel').removeByContent('Money');​

有关完整的 JS 代码,请参阅预览。

阿拉伯数字:

预览 - http://jsfiddle.net/ahzPs/1/

$('.CellLabel').contains('Money').remove();​

有关完整的 JS 代码,请参阅预览。

3:

预览 - http://jsfiddle.net/mWtzw/

$('.CellLabel').filter(function() {
    return $(this).html().indexOf('Money') != -1;
}).remove();​

您可以使用包含选择器方法:

$('td:contains("$ 0000,000.0000")').parent().hide();  //to hide
$('td:contains("$ 0000,000.0000")').parent().remove();  //to remove

或者,如果您只想删除或隐藏包含文本的 td:

$('td:contains("$ 0000,000.0000")').hide();  //to hide
$('td:contains("$ 0000,000.0000")').remove();  //to remove
$('.cellLabel').find('td:contains("money")').remove();
// just want to remove
$('.cellLabel').find('td:contains("Money Received")').parent.remove();

 // if just want to hide
 $('.cellLabel').find('td:contains("Money Received")').parent.hide();