敏感字过滤
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="text" id="txt">
<input type="button" id="btn" value="点击">
<div id="box"></div>
<script>
var word = "tmd";
btn.onclick =function(){
var val = txt.value;
val =val.toLowerCase()//把大写转换成小写
for(var i=0;i<val.length;i++){
if(val.substr(i,word.length)==word){//substr截取的长度
val= val.replace(word,"***")//replace替换
}
}
box.innerHTML +=val;
}
</script>
</body>
</html>