<!--html部分-->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="demo.js"></script>
<title></title>
</head>
<body>
字数限制: <input type="text" name="remainingCharacters" data-length="5" id=‘remainingCharacters‘ data-model=‘Ch‘>
<h2>对文本内容进行关键字过滤</h2>
<textarea name="" id="keyWordsFiltering" cols="50" rows="10">
关键字过滤:你好这里是关键字过滤部分,以下是将要被过滤的文字,傻瓜,美女,贪色,这些字会被"*"给代替,那接下来的文字也会进行过滤比如说,游戏外挂,把你的密码账发过来!!
</textarea>
</body>
</html>
<!--JavaScript部分-->
window.onload=function(){
var _keyWordsFiltering=document.getElementById("keyWordsFiltering");
_keyWordsFiltering.onclick=function(){
var keyWordsLibs=[
"傻瓜",
"密码",
"美女",
"贪色",
/[外]{1}.{0,3}[挂]{1}/
],
keyWordsLibsLen=keyWordsLibs.length;
for (var i = 0; i < keyWordsLibsLen; i++) {
_keyWordsFiltering.value=_keyWordsFiltering.value.replace(keyWordsLibs[i],"***")
}
}
};