stripTags(val) {
return val.replace(/<\/?[^>]+>/gi, '');
}
let htmlStr = '<font style="font-family: 微软雅黑; text-align: left; color: rgb(0, 0, 0);"><font style="font-family: 微软雅黑; text-align: left; color: rgb(0, 0, 0);">hi <a style="display: inline;" href="http://www.baidu.com" id="curr-1589196169191" class="link">hi</a>那你不<img src="http://s.goutong.baidu.com/static/ueditor/images/371335731f814e778a6f47ea4cff900e.jpg" style="font-family: 微软雅黑; text-align: left; color: rgb(0, 0, 0);">不不<a style="display: inline;" href="http://www.baidu.a.com" id="curr-1589196203777" class="link">不</a><font style="font-family: 微软雅黑; text-align: left; color: rgb(0, 0, 0);"></font></font></font>'
let tempDiv = document.createElement('div');
tempDiv.innerHTML = htmlStr;
let a;
while (a = tempDiv.getElementsByTagName('a'), a.length > 0) {
a[0].outerHTML = '[链接]';
}
while (a = tempDiv.getElementsByTagName('img'), a.length > 0) {
a[0].outerHTML = '[图片]';
}
while (a = tempDiv.getElementsByTagName('table'), a.length > 0) {
a[0].outerHTML = '[表格]';
}
let poorContent = this.stripTags(tempDiv.innerHTML);
// hi [链接]那你不[图片]不不[链接]
网友评论