JS特殊符号的replace转码替换方法.
里面转的不全, 比如& 很多没有加, 自己添加把.
关于转义字符先关的网址:
-  |"|&|<|>等html字符转义 – http://blog.csdn.net/wusuopubupt/article/details/8817826
- HTML字符实体(Character Entities),转义字符串(Escape Sequence)- http://114.xixik.com/character/
<script> window.onload = function () { var xxxx = ""<>&测试代码"; alert(html_decode(xxxx)); } 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; } </script>