敏感词过滤

敏感词过滤

直接上代码:
index.html


<html>
	<head>
		<meta charset="UTF-8">
		<title>词过滤title>
		<style type="text/css">
			{
      
				padding: 0;
				margin: 0;
			}
			#res{
      
				width: 200px;
				height: 200px;
				border: 1px solid #ccc;
			}
		style>
	head>
	<body>
		<h2>敏感词过滤h2>
		<p>
			<textarea name="" rows="10" cols="30" id='area'>textarea>
		p>
		<p>
			<input type="submit" name="" id="inp" value="发布" />
		p>
		<p id="res">p>
		<script type="text/javascript">
			//用户输入的值,和正则匹配,若匹配到了,则进行替换
			 let area = document.getElementById('area');
			 let inpu = document.getElementById('inp');
			 let resu = document.getElementById('res');
			 let flog = /熊大|光头强|刘先生/g;
			 inpu.onclick = function(){
      
			 	let newRes = area.value.replace(flog,'*');
			 	console.log(newRes);//测试
			 	resu.innerHTML = newRes;
			 }
			 script>
	body>
html>

效果展示:
敏感词过滤_第1张图片
敲完收工!!!!!

你可能感兴趣的:(前端,js,javascript,css,html)