Javascript 查找文本并将其删除 jquery

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11087972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 04:23:27  来源:igfitidea点击:

Find text and remove it jquery

javascriptjquery

提问by Kenp

Possible Duplicate:
Find text string using jQuery?

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

How do you find a text string and hide it with 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>

How would I remove

我将如何删除

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

from the code using a jquery.

从使用jquery的代码。

回答by Jānis

First off, your html is a bit messy, lacks a few tags. But here you go. ;)

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

1:

1:

Preview - http://jsfiddle.net/Xpc63/1/

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

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

See preview for full JS code.

完整的 JS 代码见预览。

2:

2:

Preview - http://jsfiddle.net/ahzPs/1/

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

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

See preview for full JS code.

完整的 JS 代码见预览。

3:

3:

Preview - http://jsfiddle.net/mWtzw/

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

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

回答by tjscience

You could use the contains selector method:

您可以使用 contains 选择器方法:

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

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

Or, if you just want to remove or hide the td that contains the text:

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

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

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

回答by micadelli

$('.cellLabel').find('td:contains("money")').remove();

回答by Nishu Tayal

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

Or

或者

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