敏感字符过滤
//敏感字符过滤
export var filterWord = {
handle:function(val) {
// var str = this.loadXML('/test.xml')
var str =this.loadXML('/static/js/sensitive.txt')
var reBadWords =newRegExp(str,"ig");
// debugger
return val.replace(reBadWords,"**");
},
loadXML:function(xmlFile) {
// this.loadXML('http://192.168.0.39:8005/static/js/test.xml')
// xmlDoc.getElementsByTagName("row")[0].children[0].innerHTML
var xmlhttp,xmlDoc;
if(window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp =newXMLHttpRequest();
}
else{// code for IE6, IE5
xmlhttp =new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET",xmlFile,false);
xmlhttp.send();
var str;
var arr = xmlhttp.responseText;
for(var i =0;i < arr.length;i++) {
str +="|"+ arr[i]
}
return str;
// xmlDoc = xmlhttp.responseXML;
// var str, node = xmlDoc.getElementsByTagName("row");
// for (var i = 0; i < node.length; i++) {
// str += "|" + node[i].children[0].innerHTML
// }
// return str.substr(1)
}
};