转义分为escapeHTML和unescapeHTML,先看两个函数的实现。
/*escapeHTML 转义html脚本*/ function escapeHTML (a){ a = "" + a; return a.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");; } /*unEscapeHTML 还原html脚本*/ function unEscapeHTML(a) { a = "" + a; return a.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&").replace(/"/g, '"').replace(/'/g, "'"); }