jquery部分删除文本 [英] jquery remove text partially

查看:65
本文介绍了jquery部分删除文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用jQuery删除div中的部分文本。

Can i use jQuery to remove part of a text within a div.

如下所示:

<div class="entry">
Published May 18th 2011 - Approuved - Expire May 18 th 2012<br>Source: SuperSite
</div>

我想删除 Approuved - 2012年5月18日到期

结果将是:

 <div class="entry">
    Published May 18th 2011 <br>Source: SuperSite
    </div>


推荐答案

您可以使用jquery选择元素/ html,但是javascript有一个内置函数 replace 可以满足您的需求:

You can use jquery to select your element/html, but javascript has a builtin function replace that will do what you need:

$('div.entry').html($('div.entry')
                          .html()
                          .replace('Approuved - Expire May 18 th 2012', ''))

或使用 RegExp

如果您要替换的内容始终以开始,请使用Approuved - Expire

If what you want to replace starts always with Approuved - Expire:

$('div.entry').html($('div.entry')
                          .html()
                          .replace(/Approuved - Expire[^<]*/, ''))

这篇关于jquery部分删除文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆