![](/img/trans.png)
[英]How to use jquery/javascript replace as preg_replace in PHP?
[英]How to Use Jquery Javascript Replace
我在所見即所得中使用它替換
< pre> Hi my name is< /pre>
與
< div id="precode">Hi my name is< /div>
這是工作代碼
v=v.replace(/<pre>(.*)<\/pre>/gim,'<div id="precode">$1</div>');
除非字符串包含<br>
編輯這是代碼
if(div){div.innerHTML=this.obj.toggletext||'Spell Check'}
$('#spellcheck_words').slideToggle('slow', function() { });
if(this.xhtml&&!this.ie){
v=v.replace(/<strong>(.*)<\/strong>/gi,'<span style="font-weight: bold;">$1</span>');
v=v.replace(/(<img [^>]+[^\/])>/gi,'$1/>')
v=v.replace(/<em>(.*)<\/em>/gi,'<span style="font-weight: italic;">$1</span>')
}
編輯
$('pre').replaceWith('<div>'+$(this).html()+'</div>');
采用
$('pre').replaceWith('<div>'+$(this).html()+'</div>');
所以html被傳遞了。
要么:
v=v.replace(/<pre>((?:.|[\r\n])*)<\/pre>/gim,'<div id="precode">$1</div>');
問題不在於<br/>
,而是換行符。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.