富文本編輯器生成的HTML標(biāo)簽,進(jìn)行轉(zhuǎn)義,然后寫入數(shù)據(jù)庫,防止腳本注入:
function htmlEncode(value){ return $('div/>').text(value).html(); }
1、從數(shù)據(jù)庫拿出的轉(zhuǎn)義后的HTML標(biāo)簽內(nèi)容,先得去除轉(zhuǎn)義,然后再去除HTML標(biāo)簽,是生成縮略文字。
/*移除HTML標(biāo)簽代碼*/ function removeHTMLTag(str) { str = str.replace(/\/?[^>]*>/g,''); //去除HTML tag str = str.replace(/[ | ]*\n/g,'\n'); //去除行尾空白 //str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行 str=str.replace(/ /ig,'');//去掉 return str; } //轉(zhuǎn)意符換成普通字符 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];}); }
如果是文章詳情頁的話,直接去除轉(zhuǎn)義就可以顯示在頁面了:
//轉(zhuǎn)意符換成普通字符 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標(biāo)簽
var test=test.replace(/font-size:\w+;?/g,'');
3、js處理去掉富文本編輯的html,樣式,只顯示純文字內(nèi)容,以供列表頁使用
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">國際保險經(jīng)紀(jì)行業(yè)收入分析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">年全球保險經(jīng)紀(jì)行業(yè)市場規(guī)模為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">年國際保險經(jīng)紀(jì)行業(yè)市場規(guī)模:億美元/span>/p> p style="margin: 19.5pt 0cm; text-indent: 24.1pt; text-align: center;"> img alt="" src="/baoxian/userfiles/1/images/back/news/2018/01/11.png" style="width: 493px; height: 296px;" />/p> 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">2./span>/b>b>span style="font-family:宋體;mso-bidi-font-family:宋體;color:#252525">國際保險經(jīng)紀(jì)行業(yè)并購分析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 style="font-family:宋體;mso-bidi-font-family:宋體;color:#252525">保險經(jīng)紀(jì)公司并購較為頻繁,span lang="EN-US">2011/span>年并購數(shù)量為span lang="EN-US">351/span>件,且呈現(xiàn)增長趨勢。一股保險行業(yè)的并購風(fēng)潮正席卷全球各個市場。如意大利投資集團(tuán)span lang="EN-US">Exor/span>收購再保險公司span lang="EN-US">PartnerRe/span>、韜睿惠悅與韋萊集團(tuán)、韋萊與法國保險經(jīng)紀(jì)公司span lang="EN-US">GrasSavoye/span>、瑞士保險集團(tuán)span lang="EN-US">ACE/span>并購span lang="EN-US">Chubb/span>以及美國保險公司span lang="EN-US">Anthem/span>收購span lang="EN-US">Cigna/span>。而這些不過是近年來保險業(yè)并購案清單的一小部分。span lang="EN-US">o:p>/o:p>/span>/span>/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 style="font-family:宋體;mso-bidi-font-family:宋體;color:#252525">然而,在熱鬧喧囂的并購消息背后卻是嚴(yán)酷的現(xiàn)實(shí)。波士頓咨詢(span lang="EN-US">BCG/span>)對span lang="EN-US">1990/span>~span lang="EN-US">2014/span>年間span lang="EN-US">778/span>件涉及保險業(yè)的并購案進(jìn)行了分析,對并購后一年內(nèi)的股東總回報進(jìn)行了追蹤,最終發(fā)現(xiàn)只有span lang="EN-US">51%/span>的并購能實(shí)際創(chuàng)造價值,而span lang="EN-US">49%/span>的并購案則摧毀了公司的價值。近半數(shù)并購案失敗可歸咎為三大原因:并購準(zhǔn)備和執(zhí)行、并購后整合以及并購時機(jī)。span lang="EN-US">o:p>/o:p>/span>/span>/p> 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">3./span>/b>b>span style="font-family:宋體;mso-bidi-font-family:宋體;color:#252525">保險業(yè)持續(xù)大整合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 style="font-family:宋體;mso-bidi-font-family:宋體;color:#252525">未來span lang="EN-US">5/span>年,多個宏觀層面的因素將繼續(xù)推動保險業(yè)進(jìn)行整合。首先是監(jiān)管繼續(xù)收緊,尤其是對資本充足率的要求將繼續(xù)提升,無論是獨(dú)立保險商還是綜合集團(tuán)都將感到更大的資金壓力。利率和投資回報將繼續(xù)保持較低水平(至少在成熟市場),使傳統(tǒng)的壽險業(yè)務(wù)盈利能力受到限制。span lang="EN-US">o:p>/o:p>/span>/span>/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 style="font-family:宋體;mso-bidi-font-family:宋體;color:#252525">此外,新興競爭對手的威脅也不可小覷,甚至大型連鎖超市和電信公司都有可能顛覆保險行業(yè)的價值鏈。這些企業(yè)不但擁有價值連城的消費(fèi)者數(shù)據(jù),而且擁有與客戶之間的“最后一公里”連接。在新的運(yùn)營模式下,傳統(tǒng)保險企業(yè)難以掌控整條價值鏈,且容易成為新型商業(yè)模式的顛覆目標(biāo),例如一些網(wǎng)絡(luò)聚合搜索產(chǎn)品能夠?yàn)橄M(fèi)者提供價格透明的產(chǎn)品對比。span lang="EN-US">o:p>/o:p>/span>/span>/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 style="font-family:宋體;mso-bidi-font-family:宋體;color:#252525">資金充裕的大型保險公司可以利用投資抵御創(chuàng)新帶來的威脅,而那些只聚焦于內(nèi)部運(yùn)營,對外部變化視而不見的中型企業(yè)將面臨更激烈的競爭。對于保險公司來說,了解消費(fèi)者的行為和需求是至關(guān)重要的能力,然而建設(shè)必需的大數(shù)據(jù)技術(shù)、文化和團(tuán)隊帶來的成本巨大,讓規(guī)模較小的保險公司難以承受。對于保險企業(yè)來說,有機(jī)成長的機(jī)會非常有限。成熟市場已經(jīng)進(jìn)入到整合周期內(nèi),盡管新興市場存在著發(fā)展機(jī)遇,但市場環(huán)境非常復(fù)雜。要在新市場形成規(guī)模效應(yīng),并購顯然仍是各大保險企業(yè)的明智之選。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 style="font-family:宋體;mso-bidi-font-family:宋體;color:#252525">世界排名前十保險經(jīng)紀(jì)公司國際業(yè)務(wù)占比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"> img alt="" src="/baoxian/userfiles/1/images/back/news/2018/01/12.png" style="width: 554px; height: 289px;" />/p> 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">4./span>/b>b>span style="font-family:宋體;mso-bidi-font-family:宋體;color:#252525">國際保險經(jīng)紀(jì)行業(yè)利潤水平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 style="font-family:宋體;mso-bidi-font-family:宋體;color:#252525">目前,span lang="EN-US">2015/span>年全球保險經(jīng)紀(jì)行業(yè)收入達(dá)span lang="EN-US">581.3/span>億美元,國際保險經(jīng)紀(jì)行業(yè)利潤水平維持在span lang="EN-US">10~25%/span>之間。span lang="EN-US">o:p>/o:p>/span>/span>/p>'; description = description.replace(/(\n)/g, ""); description = description.replace(/(\t)/g, ""); description = description.replace(/(\r)/g, ""); description = description.replace(/\/?[^>]*>/g, ""); description = description.replace(/\s*/g, ""); console.log(description) /script>
4、jQuery JavaScript正則表達(dá)式與\n代替BR>
Lee TaylorTeneff給出了該問題的處理方式:
var str = document.getElementById('mydiv').innerHTML;
document.getElementById('mytextarea').innerHTML = str.replace(/br\s*[\/]?>/gi, "\n");
or using jQuery:
var str = $("#mydiv").html();
var regex = /br\s*[\/]?>/gi;
$("#mydiv").html(str.replace(regex, "\n"));
5、要去除html標(biāo)簽,圖片,換行,回車等
description = description.replace(/(\n)/g, ""); description = description.replace(/(\t)/g, ""); description = description.replace(/(\r)/g, ""); description = description.replace(/\/?[^>]*>/g, ""); description = description.replace(/\s*/g, "");
6、腳本之家小編寫的一個替換fackeditor中的多余br與空行的
//加強(qiáng)替換主要是考慮多個br的問題 function doRepAdvance(s){ var str=s.replace(/p>br type="_moz">\/p>/ig,""); str=str.replace(/br type="_moz">\nnbsp;\/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 \/>\nnbsp;\/p>/ig, "/p>"); str=str.replace(/br>\nnbsp;\/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; }
到此這篇關(guān)于js處理富文本編輯器轉(zhuǎn)義、去除轉(zhuǎn)義、去除HTML標(biāo)簽的正則的文章就介紹到這了,更多相關(guān)編輯器轉(zhuǎn)義、去除轉(zhuǎn)義、去除HTML標(biāo)簽內(nèi)容請搜素腳本之家以前的文章或下面相關(guān)文章,希望大家以后多多支持腳本之家!
標(biāo)簽:湖州 哈密 大興安嶺 ???/a> 泰安 涼山 本溪 常州
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《js處理網(wǎng)頁編輯器轉(zhuǎn)義、去除轉(zhuǎn)義、去除HTML標(biāo)簽的正則》,本文關(guān)鍵詞 處理,網(wǎng)頁,編輯器,轉(zhuǎn)義,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。