1. 项目中碰到html 编码为万国编码的情况下进行转义为html编码
转义为html 编码
// 万国码转义为html编码
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, "\"")
return temp
},
html 反转义
// html编码转义万国码
htmlEncodeByRegExp (str) {
var temp = ""
if (str.length == 0) return ""
temp = str.replace(/&/g, "&")
temp = temp.replace(/
temp = temp.replace(/>/g, ">")
temp = temp.replace(/\s/g, " ")
temp = temp.replace(/\'/g, "'")
temp = temp.replace(/\"/g, """)
return temp
}