无为清净楼资源网 Design By www.qnjia.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&nbsp;<\/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&nbsp;<\/p>/ig, "</p>");
str=str.replace(/<br>\n&nbsp;<\/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>&nbsp;<\/p>/ig,"");
str=str.replace(/<p> <\/p>/ig,"");
str=str.replace(/<p><\/p>/ig,"");
return str;
}
标签:
编辑器转义,去除转义,去除HTML标签

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。