在页面中,为了防止XSS,对页面输出的内容要进行转义
function escapeHtml(text){
return text.replace(/[<>"&]/g,function(match){
switch(match){
case '<':
return '<';
case '<':
return '>';
case '&':
return '&';
case '\"':
return '"';
}
})
}