金狮镖局 Design By www.egabc.com
富文本编辑器生成的HTML标签,进行转义,然后写入数据库,防止脚本注入:
function htmlEncode(value){ return $('<div/>').text(value).html(); }
1、从数据库拿出的转义后的HTML标签内容,先得去除转义,然后再去除HTML标签,是生成缩略文字。
/*移除HTML标签代码*/ function removeHTMLTag(str) { str = str.replace(/<\/"'}; return str.replace(/&(lt|gt|nbsp|amp|quot);/ig,function(all,t){return arrEntities[t];}); }
如果是文章详情页的话,直接去除转义就可以显示在页面了:
//转意符换成普通字符 function escape2Html(str) { var arrEntities={'lt':'<','gt':'>','nbsp':' ','amp':'&','quot':'"'}; return str.replace(/&(lt|gt|nbsp|amp|quot);/ig,function(all,t){return arrEntities[t];}); }
2、JS正则过滤(去除)富文本编辑器中的FONT-SIZE标签
var test=test.replace(/font-size:\w+;"htmlcode">
<script type="text/javascript"> var description = '<p style="margin-top:19.5pt;margin-right:0cm;margin-bottom:19.5pt;margin-left: 0cm;text-indent:24.1pt;mso-char-indent-count:2.0;mso-pagination:widow-orphan"> <b><span lang="EN-US" style="font-family:宋体;mso-bidi-font-family:宋体;color:#252525">1.</span></b><b><span style="font-family:宋体;mso-bidi-font-family:宋体;color:#252525">国际保险经纪行业收入分析<span lang="EN-US"><o:p></o:p></span></span></b></p> <p style="margin-top:19.5pt;margin-right:0cm;margin-bottom:19.5pt;margin-left: 0cm;text-indent:24.0pt;mso-char-indent-count:2.0;mso-pagination:widow-orphan"> <span lang="EN-US" style="font-family:宋体;mso-bidi-font-family:宋体;color:#252525">2010</span><span style="font-family:宋体;mso-bidi-font-family:宋体;color:#252525">年全球保险经纪行业市场规模为<span lang="EN-US">437.56</span>亿美元,<span lang="EN-US">2015</span>年增长至<span lang="EN-US">581.3</span>亿美元。<span lang="EN-US"><o:p></o:p></span></span></p> <p align="center" style="margin-top:19.5pt;margin-right:0cm;margin-bottom:19.5pt; margin-left:0cm;text-align:center;mso-pagination:widow-orphan"> <span lang="EN-US" style="font-family:宋体;mso-bidi-font-family:宋体;color:#252525">2010-2015</span><span style="font-family:宋体;mso-bidi-font-family:宋体;color:#252525">年国际保险经纪行业市场规模:亿美元</span></p> <p style="margin: 19.5pt 0cm; text-indent: 24.1pt; text-align: center;"> <img alt="" src="/UploadFiles/2021-04-02/11.png">4、jQuery JavaScript正则表达式与\n代替<BR>
Lee TaylorTeneff给出了该问题的处理方式:
var str = document.getElementById('mydiv').innerHTML;
document.getElementById('mytextarea').innerHTML = str.replace(/<br\s*[\/]"\n");or using jQuery:
var str = $("#mydiv").html();
var regex = /<br\s*[\/]"#mydiv").html(str.replace(regex, "\n"));5、要去除html标签,图片,换行,回车等
description = description.replace(/(\n)/g, ""); description = description.replace(/(\t)/g, ""); description = description.replace(/(\r)/g, ""); description = description.replace(/<\/""); description = description.replace(/\s*/g, "");6、小编写的一个替换fackeditor中的多余br与空行的
//加强替换主要是考虑多个br的问题 function doRepAdvance(s){ var str=s.replace(/<p><br type="_moz"><\/p>/ig,""); str=str.replace(/<br type="_moz">\n <\/p>/ig, "</p>"); str=str.replace(/<br type="_moz">\n<\/p>/ig, "</p>"); str=str.replace(/<br type="_moz">\n\r<\/p>/ig, "</p>"); str=str.replace(/<br type="_moz"><\/p>/ig,"</p>"); str=str.replace(/<br \/>\n <\/p>/ig, "</p>"); str=str.replace(/<br>\n <\/p>/ig, "</p>"); str=str.replace(/<br \/>\n<\/p>/ig, "</p>"); str=str.replace(/<br \/>\n\r<\/p>/ig, "</p>"); str=str.replace(/(<br>\n){1,}<\/p>/ig,"</p>"); str=str.replace(/(<br>){1,}<\/p>/ig,"</p>"); str=str.replace(/<br>\n<\/p>/ig, "</p>"); str=str.replace(/<br><\/p>/ig,"</p>"); str=str.replace(/<p> <\/p>/ig,""); str=str.replace(/<p> <\/p>/ig,""); str=str.replace(/<p> <\/p>/ig,""); str=str.replace(/<p><\/p>/ig,""); return str; }
金狮镖局 Design By www.egabc.com
金狮镖局
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
金狮镖局 Design By www.egabc.com
暂无js处理网页编辑器转义、去除转义、去除HTML标签的正则的评论...
更新日志
2024年09月23日
2024年09月23日
- Merryland《Merryland》[320K/MP3][69.48MB]
- 苏芮.1991-停在我心里的温柔【福茂】【WAV+CUE】
- 苏慧伦.2020-面面Every.Side.of.Me【相信音乐】【WAV+CUE】
- 群星.1991-不一样的感觉REMIX【宝丽金】【WAV+CUE】
- 银霞.1983-《你那好冷的小手》珍藏纪念版[WAV分轨]
- 银霞.2002-《国语巨星专辑VOL.3》2CD台湾版[WAV+CUE]
- 金池刘罡《昨日情歌HQ》头版限量编号[低速原抓WAV+CUE]
- 段奥娟.2024-23·岁碎念【白米范】【FLAC分轨】
- 顺子.2001-昨日·唯一·更多·顺子自选辑【魔岩】【WAV+CUE】
- 无印良品.1999-私藏三首·原创相对论(EP)【滚石】【WAV+CUE】
- Merryland《Merryland》[FLAC/分轨][170.22MB]
- 庄锭欣 ELKIE《没有你的未来》[320K/MP3][15.78MB]
- 庄锭欣 ELKIE《没有你的未来》[FLAC/分轨][36MB]
- TchaikovskySwanLake,Op.20柴可夫斯基天鹅湖(2013)SACD[Hi-Res]
- 24bit达人艺典《琴歌终极版》整轨WAV+CUE