How to Use Jquery Javascript Replace
I'm using this in my wysiwyg to r开发者_开发百科eplace
< pre> Hi my name is< /pre>
with
< div id="precode">Hi my name is< /div>
This is the working code code
v=v.replace(/<pre>(.*)<\/pre>/gim,'<div id="precode">$1</div>');
This works fine unless the string contains a < br>
EDIT This is the code
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>')
}
EDIT
$('pre').replaceWith('<div>'+$(this).html()+'</div>');
use
$('pre').replaceWith('<div>'+$(this).html()+'</div>');
so html gets passed over.
Or:
v=v.replace(/<pre>((?:.|[\r\n])*)<\/pre>/gim,'<div id="precode">$1</div>');
Problem is not with <br/>
, but with new-line characters.
精彩评论