/*正则表达式 替换括号,尖括号等*/ function toTxt(str) { var RexStr = /\<|\>|\"|\'|\&/g str = str.replace(RexStr, function(MatchStr) { switch (MatchStr) { case "<": return "<"; break; case ">": return ">"; break; case "\"": return """; break; case "'": return "'"; break; case "&": return "&"; break; default: break; } }) return str; }
?
例:
???? 替换前:<script>alert('test---test');</script>
???? 替换后:< script> alert('test---test');< /script>