为了保证页面输出安全,我们经常需要对一些特殊的字符进行转义,请写一个函数escapeHtml,将<, >, &, “进行转义
function escapeHtml(str) {
return str.replace(/[<>”&]/g, function(match) {
switch (match) {
case “<”: return “<”; case “>”:
return “>”;
case “&”:
return “&”;
case “””:
return “"”;
}
});
}