//定义一个转换html转义特殊字符的方法
function htmlEscape(htmlStr) {
return htmlStr.replace(/[<>|"&]/g, (match) => {
switch (match) {
case '<':
return '<';
case '>':
return '>';
case '"':
return '"';
case '&':
return '&';
}
});
}
//定义一个转换htmlh还原特殊字符的方法
function htmlUnEscape(str) {
return str.replace(/<|>|"|&/g, (match) => {
switch (match) {
case '<':
return '<';
case '>':
return '>';
case '"':
return '"';
case '&':
return '&';
}
});
}
js exercises (escaping and restoring special characters in html)
Guess you like
Origin blog.csdn.net/weixin_46611729/article/details/109553438
Recommended
Ranking