- var REGX_html_ENCODE = /"|&|'|<|>|[\\x00-\\x20]|[\\x7F-\\xFF]|[\\u0100-\\u2700]/g;
- function encodeHtml(s){
- return (typeof s != "string") ? s :
- s.replace(REGX_HTML_ENCODE,
- function($0){
- var c = $0.charCodeAt(0), r = ["&#"];
- c = (c == 0x20) ? 0xA0 : c;
- r.push(c); r.push(";");
- return r.join("");
- });
- }
- //该片段来自于http://www.codesnippet.cn/detail/291020136777.html
来源: http://www.codesnippet.cn/detail/291020136777.html