过滤html元素,把中文过滤出来

251 阅读1分钟

作为一个资深BP党,复制文档必会技能 直接贴代码,运行后直接将你要过滤的内容复制到输入框里即可

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>匹配中文和中文字符</title>
	</head>
	<body>
		<div id="">
			<h5>输入待验证文字:</h5>
			<textarea rows="7" cols="10" id="text" style="width: 100%;"></textarea>
			<button type="button"  onclick="filter()">筛选</button>
			<h5>筛选结果:</h5>
			<textarea rows="7" cols="10" id="result" style="width: 100%;">
			</textarea>
		</div>
		<script type="text/javascript">
			function filter(){
				var value=document.getElementById("text").value
				var  reg=/<[^>]+>/gim;;
				console.log(value.replace(reg,""))
				var string=value.replace(reg,"")
				var reg2=/&nbsp;/g
				const result=string.replace(reg2,"")
				document.getElementById("result").value=result
			}	
		</script>
	</body>
</html>