时间:2021-07-01 10:21:17 帮助过:20人阅读
function del_html_tags(str,reallyDo,replaceWith) {
var e=new RegExp(reallyDo,"g");
words = str.replace(e, replaceWith);
return words;
}
str是目标字符串
reallyDo是替换谁
replaceWith是替换成什么。
var replyText="<p>恭恭敬敬恭恭敬敬恭恭敬敬</p><p><br /></p><p>恭恭敬敬恭恭敬敬恭恭敬敬恭恭敬敬</p><p><br /></p>";
eg:
代码如下:
replyText= del_html_tags(replyText,"<br />"," ");
replyText= del_html_tags(replyText,"<p>","");
replyText= del_html_tags(replyText,"</p>","");
就可以得到
"恭恭敬敬恭恭敬敬恭恭敬敬 恭恭敬敬恭恭敬敬恭恭敬敬恭恭敬敬"