其他分享
首页 > 其他分享> > 去掉html标签

去掉html标签

作者:互联网

// 去掉html标签
function delHtmlTag(str){
    return str ? str.replace(/<[^>]+>/g,"") : '';//去掉所有的html标记
}

/**
 * 字符串是否含有html标签的检测
 * @param htmlStr
 */
function checkHtml(htmlStr) {
    var  reg = /<[^>]+>/g;
    return reg.test(htmlStr);
}

/**
 * 将富文本转义的html代码 反转义
 * @param str
 */
function htmlDecodeByRegExp (str){
    var s = "";
    if(str.length == 0) return "";
    s = str.replace(/&amp;/g,"&");
    s = s.replace(/&lt;/g,"<");
    s = s.replace(/&gt;/g,">");
    s = s.replace(/&nbsp;/g," ");
    s = s.replace(/&#39;/g,"\'");
    s = s.replace(/&quot;/g,"\"");
    return s;  
}

标签:function,return,标签,replace,html,str,htmlStr,去掉
来源: https://blog.csdn.net/qq_30607437/article/details/120087854