过滤HTML只保留指定的标签比如p,img,br

<!DOCTYPE html>
<html>
<head>
	<title>过滤HTML只保留指定的标签比如p,img,br</title>
	<meta charset='utf-8'/>
</head>
<body>
	<script type="text/javascript">
		var rt = '<p>&nbsp;&nbsp;&nbsp;123<br/>46</p><IMG src="https://avatar-static.segmentfault.com/309/105/3091058249-1030000000476139_big64"/><p>';//需要过虑的内容  
		rt = rt.replace(/<\/?(?!p|P|img|IMG|Img|br|BR|Br)[^>]*>/g, ''); // 去除HTML tag,保留p,img,br标签  
		rt = rt.replace(/[ | ]*\n/g, '\n'); // 去除行尾空白
		rt = rt.replace(/&nbsp;/ig, '');// 去掉&nbsp; 
		console.log(rt);
	</script>
</body>
</html>
DarinDed 11个月前

Instead of criticism write the variants. sassa


DarinDed 11个月前

I am final, I am sorry, but it not absolutely approaches me. Who else, what can prompt? sassa


DarinDed 11个月前

You have hit the mark. In it something is and it is good idea. I support you. sassa