js过滤html代码

escape = function(text){
var REGX_HTML_ENCODE = /"|&|'|<|>|[\x00-\x20]|[\x7F-\xFF]|[\u0100-\u2700]/g;
return text.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(""); 
});
}

 

posted @ 2014-03-06 10:00  taotaowill  阅读(367)  评论(0编辑  收藏  举报