使用jquery从段落中删除某些单词

前端之家收集整理的这篇文章主要介绍了使用jquery从段落中删除某些单词前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个这样的网页:
<p class="author">By ... on Jan 23,2012</p>
<p class="content">(some content)</p>

<p class="author">By ... on Jan 23,2012</p>
<p class="content">(some content)</p>

...

我想使用jquery从p.author中删除单词“By”和“on”,结果将是:

<p class="author">... Jan 23,2012</p>
<p class="content">(some content)</p>
...

谢谢!

解决方法

$(".author").each( function(){
    var text = this.firstChild.nodeValue;
    this.firstChild.nodeValue = text.replace( /(^By|\bon\b)/g,"" );
});
原文链接:https://www.f2er.com/jquery/175747.html

猜你在找的jQuery相关文章