js过滤(去除)富文本编辑器中的html标签和换行回车等标记的正则表达式
2013-09-30 10:37
811 查看
一段这样的Html包裹的文字:
var description="<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>"
要去除html标签,图片,换行,回车等
得到结果:dsfdssdfdsfssadasasdsaddfds
参考http://www.itlead.com.cn/article/html/148/2011-08-16/content-1769.shtml
var description="<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>"
要去除html标签,图片,换行,回车等
description = description.replace(/(\n)/g, ""); description = description.replace(/(\t)/g, ""); description = description.replace(/(\r)/g, ""); description = description.replace(/<\/?[^>]*>/g, ""); description = description.replace(/\s*/g, "");
得到结果:dsfdssdfdsfssadasasdsaddfds
参考http://www.itlead.com.cn/article/html/148/2011-08-16/content-1769.shtml
相关文章推荐
- jsp text 标签设置只允许输入数字
- js 输入int类型数字后自动在后面加.00,输入double型保留小数点后两位
- javascript ==和===的区别
- Js事件大全
- javascript function new this
- [转载]js正则表达式/replace替换变量方法
- js获取鼠标位置(兼容ie和火狐)
- JavaScript世界的一等公民 - 函数
- [转] js 事件冒泡 阻止
- javascript中模拟java类
- js版 3D坦克大战 V0.2
- 今天星期几js
- Jsp中如何在<c:forEach >标签内获取items集合的长度方法
- js防止表单重复提交的两种方法
- JS实现金额转换(将输入的阿拉伯数字)转换成中文的实现代码
- Javascript匿名函数自调用方法 (function(){})()用法
- JS周期执行与延迟执行
- JS frame 使用
- frame,iframe,frameset之间的关系与区别
- FireFox下使用Javascript上传大文件(php版本)