<!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>
JS过滤(去除)富文本编辑器中的HTML标签和换行回车等标记的正则表达式
最新推荐文章于 2024-06-20 12:00:26 发布
本文介绍了一种使用JavaScript正则表达式去除富文本编辑器中HTML标签、换行及空白字符的方法。通过简单的代码实现,可以有效清理文本内容,便于进一步处理或显示纯文本信息。
富文本编辑器中的HTML标签和换行回车等标记的正则表达式&spm=1001.2101.3001.5002&articleId=54965990&d=1&t=3&u=19adf440735f468b8dfdf8623cf1a89b)
2915

被折叠的 条评论
为什么被折叠?



