分享javascript来对html编码和解码
/** *htmlEncode编码 */ function htmlEncode(str) { var s = ""; if (str.length == 0) return ""; s = str.replace(/&/g, "&"); s = s.replace(/</g, "<"); s = s.replace(/>/g, ">"); s = s.replace(/\'/g, "'"); s = s.replace(/\"/g, """); return s; } /** *htmlDecode解码 */ function htmlDecode(str) { var s = ""; if (str.length == 0) return ""; s = str.replace(/&/g, "&"); s = s.replace(/</g, "<"); s = s.replace(/>/g, ">"); s = s.replace(/'/g, "\'"); s = s.replace(/"/g, "\""); return s; }