您的位置:首页 > Web前端 > JavaScript

JS过滤(去除)富文本编辑器中的HTML标签和换行回车等标记的正则表达式

2017-02-10 11:29 671 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> JS过滤(去除)富文本编辑器中的html标签和换行回车等标记的正则表达式</title>
<script language="javascript">
function show(){
var test="<p>\n\t<img src=\"http://localhost/Scripts/KindEditor/Editor/plugins/emoticons/images/0.gif\" alt=\"\" border=\"0\" />ds<em>fds</em>\n</p>\n<p>\n\ts<span style=\"font-size:16px;\">dfd</span>sf<img src=\"http://localhost/Scripts/KindEditor/Editor/plugins/emoticons/images/19.gif\" alt=\"\" border=\"0\" />ds<strong>fdsfds</strong>\n</p>\n<p>\n\t<br />\n<strong></strong>\n</p>\n<p align=\"center\">\n\t<strong>d<span style=\"font-family:FangSong_GB2312;\">ssa</span>dasasdsad<u>dfds</u><br />\n</strong>\n</p>"
test = test.replace(/(\n)/g, "");
test = test.replace(/(\t)/g, "");
test = test.replace(/(\r)/g, "");
test = test.replace(/<\/?[^>]*>/g, "");
test = test.replace(/\s*/g, "");
document.getElementById("sd").innerHTML=test;
}
</script>
</head>

<body onload="show();">
<div id="sd"></div>
</body>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息