js之敏感词过滤

js之敏感词过滤_第1张图片
HTML




表单留言信息过滤



    

留言面板



  

 
js:
var oPublish = document.getElementById('publish');
var oMessage = document.getElementById('message');
var oReceive = document.getElementById('receive');
var sensitiveWords = ['赵成亮','吴旭东','薛江强','老王','孙毅','丁函','尚启'];
oPublish.onclick = function(){
    var sMessage = oMessage.value;
    if(sMessage == ''){
        alert('请输入留言!');
        return false;
    }
//    sensitiveWords.forEach.(function(v){
//        sMessage = sMessage.replace(v , '***');
//    });
    sensitiveWords.forEach(function (v) {
        while(sMessage.indexOf(v) !== -1){
            sMessage = sMessage.replace(v, '***');
        }
    });
    var oLi = document.createElement('li');
    oLi.innerHTML =sMessage;
    oReceive.appendChild(oLi);
    oMessage.value = '';
}

  

 

你可能感兴趣的:(js之敏感词过滤)