通过js和正则表达式过滤html标签

七海恋空 2019-04-30 浏览(0 评论(0

过滤DOCCONTENT的br标签

<script>
//过滤DOCCONTENT的br标签
function removeHTMLTag(str) {
str = str.replace(/<\/?[^>]*>/g,''); //去除HTML tag
str = str.replace(/[ | ]*\n/g,'\n'); //去除行尾空白
//str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
str=str.replace(/ /ig,'');//去掉
return str;
}
var content="<TRS_DOCUMENT FIELD="DOCCONTENT" CODEFILTERED="TRUE" NUM="180"></TRS_DOCUMENT> "
document.write(removeHTMLTag(content));
</script>