如何将html转义后的字符再转义回来
参考:
JS转换HTML转义符
Decode & back to & in JavaScript
还是stackoverflow上的回答比较专业
var encodedStr = 'hello & world';
var parser = new DOMParser;
var dom = parser.parseFromString(
'<!doctype html><body>' + encodedStr,
'text/html');
var decodedString = dom.body.textContent;
console.log(decodedString);
借此写个函数
function decoder(str){
var parser = new DOMParser;
var dom = parser.parseFromString(
'<!doctype html><body>' + str,
'text/html');
var decodedString = dom.body.textContent;
return decodedString;
}