Just do your best!!!

JavaScript转义HTML的方法

(function(){
    this.encodeHtml = function(str){
        var s = "";
        if (str.length == 0) return "";
        s = str.replace(/&/g, "&");
        s = str.replace(/</g, "&lt;");
        s = s.replace(/>/g, "&gt;");
        s = s.replace(/ /g, "&nbsp;");
        s = s.replace(/'/g, "&#39;");
        s = s.replace(/&quot;/g, "&quot;");
        s = s.replace(/\n/g, "<br>"); 
      return s;   
    };
    this.decodeHtml = function(str){
        var s = "";
        var s = "";
        if (str.length == 0) return "";
        s = str.replace(/&amp;/g, "&");
        s = str.replace(/&lt;/g, "<");
        s = s.replace(/&gt;/g, ">");
        s = s.replace(/&nbsp;/g, " ");
        s = s.replace(/&#39;/g, "'");
        s = s.replace(/&quot;/g, "&quot;");
        s = s.replace(/<br>/g, "\n");
      return s;   
    };
})();

调用window.encodeHtml(要转义的字符),获取转义的结果。
调用window.decodeHtml (转义的字符),获取反转义的结果。