出现原因: 后台管理系统使用了富文本编辑器进行编辑时候,用户竟然输入带html标签的文章内容或者被后台解析转义了特定标签,导致前台显示的时候得到都内容为如下图所示:
所以会导致显示出来的就是html标签。
解决:
/**
解决内容被转义问题
*/
function htmlDecodeByRegExp(str) {
var temp = "";
if (str.length == 0) return "";
temp = str.replace(/&/g, "&");
temp = temp.replace(/</g, "<");
temp = temp.replace(/>/g, ">");
temp = temp.replace(/ /g, " ");
temp = temp.replace(/'/g, "'");
temp = temp.replace(/"/g, '"');
temp = temp.replace(/↵/g, "");
return temp;
}