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

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

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

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

谢谢!

解决方法

  1. $(".author").each( function(){
  2. var text = this.firstChild.nodeValue;
  3. this.firstChild.nodeValue = text.replace( /(^By|\bon\b)/g,"" );
  4. });

猜你在找的jQuery相关文章