javascript – 如何从字符串中删除span标签?

前端之家收集整理的这篇文章主要介绍了javascript – 如何从字符串中删除span标签?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要从字符串中删除span标记.它是否可行.?

我的意见是这个

  1. In open <span class="">court</span> at 11:01 a.m.)
  2. THE <span class="">COURT</span>: Our interpreter.
  3. (NOTE: Spanish interpreter Rosa Lopez-Gaston sworn.)
  4. SPEAKER 2: Judy Faviell for the State.
  5. SPEAKER 1: Carey Bhalla for Mr. Garcia,who is present in custody,Your Honor.
  6. SPEAKER 2: Judge,we do have a change of plea,which I will tender to the <span class="">Court</span>.
  7. THE <span class="">COURT</span>:

输出就是这个

  1. In open court at 11:01 a.m.)
  2. THE COURT: Our interpreter.
  3. (NOTE: Spanish interpreter Rosa Lopez-Gaston sworn.)
  4. SPEAKER 2: Judy Faviell for the State.
  5. SPEAKER 1: Carey Bhalla for Mr. Garcia,Your Honor.
  6. SPEAKER 2: Judge,which I will tender to the <span class="">Court</span>.
  7. THE COURT:

解决方法

对于您编辑的问题,您可以这样做:
  1. var str = // your string here
  2.  
  3. str = str.replace(/<\/?span[^>]*>/g,"");

演示:http://jsfiddle.net/vXXJ6/

猜你在找的JavaScript相关文章