标签:
function html_encode(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, "‘"); s = s.replace(/\"/g, """); s = s.replace(/\n/g, "<br>"); return s; }
function html_decode(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, "\‘"); s = s.replace(/"/g, "\""); s = s.replace(/<br>/g, "\n"); return s; }
JavaScript 的HTML转义方法 html_encode 和 html_decode
标签:
原文地址:http://www.cnblogs.com/xiguain/p/4520504.html