/** * 将HTML转义为实体 */ String.prototype.escapeHtml=function(){ var s = ""; if(Utils.isNullorEmpty(this)) return ""; s = this.replace(/&/g, "&"); s = s.replace(/</g, "<"); s = s.replace(/>/g, ">"); s = s.replace(/ /g, " "); s = s.replace(/\'/g, "'"); s = s.replace(/\"/g, """); s = s.replace(/\n/g, "<br>"); return s; } /** * 将实体转回为HTML */ String.prototype.unescapeHtml=function(){ var s = ""; if(Utils.isNullorEmpty(this)) return ""; s = this.replace(/&/g, "&"); s = s.replace(/</g, "<"); s = s.replace(/>/g, ">"); s = s.replace(/ /g, " "); s = s.replace(/'/g, "\'"); s = s.replace(/"/g, "\""); s = s.replace(/<br>/g, "\n"); return s; }
// 判断字符是否为空 Utils.isNullorEmpty=function(str){ if((str==null||str==""||str==undefined||str=="undefined")&&(str!=0||str!="0")) return true; else return false; }