Jquery Javascript替换字符串

Jquery Javascript替换字符串,jquery,replace,wysiwyg,Jquery,Replace,Wysiwyg,我使用的wysiwyg编辑器使用span样式替换。我修改添加了一个代码块 v=v.replace(/<strong>(.*)<\/strong>/gi,'<span style="font-weight: bold;">$1</span>'); v=v.replace(/<pre>(.*)<\/pre>/gi,'<div id="precode"> $1 </div>'); v=v.replace

我使用的wysiwyg编辑器使用span样式替换
。我修改添加了一个代码块

v=v.replace(/<strong>(.*)<\/strong>/gi,'<span style="font-weight: bold;">$1</span>');
v=v.replace(/<pre>(.*)<\/pre>/gi,'<div id="precode"> $1 </div>');
v=v.replace(/(.*)/gi,$1');
在我用

v=v.replace(/(.*)/gi,$1');
我一直在寻找,无法确定任何关于替换的信息。有人能解释一下吗

有人能解释一下这部分代码吗?我相信它也会帮助其他人

if(id=='style'){
                var sel=document.createElement('select'),
                styles=obj.styles||[['Style',''],['Paragraph','<p>'],['Header 1','<h1>'],['Header 2','<h2>'],['Header 3','<h3>'],['Header 4','<h4>'],['Header 5','<h5>'],['Header 6','<h6>'],['CodeBlock','<pre>']],
                sl=styles.length, x=0;
                sel.className='testyle'; sel.onchange=new Function(this.n+'.ddaction(this,"formatblock")');
                for(x;x<sl;x++){
                    var style=styles[x];
                    sel.options[x]=new Option(style[0],style[1])
                }
。替换(/(.*)/gi,'
这其中是否有什么原因导致it向每个应用程序添加新样式 线

if(id=='style'){
var sel=document.createElement('select'),
styles=obj.styles | |【】、【】、【】、【段落】、【段落】、【标题1】、【标题2】、【标题3】、【标题4】、【标题5】、【标题6】、【代码块】、【】,
sl=styles.length,x=0;
sel.className='testyle';sel.onchange=new函数(this.n+'.ddaction(this,“formatblock”);

对于(x;x当您传递字符串以在/../gi中查找时,它会查找原始字符串中该字符串的所有出现处,并将其替换为我们作为第二个参数传递的字符串。它不会修改原始字符串,因此您必须将其输出分配给某个变量才能使用它。我希望这是有意义的。

replace是一个字符串方法ch用另一个字符串替换所需的字符串。所需的替换也可以是正则表达式。在您的情况下,这意味着它将找到所有
标记,并将它们替换为
标记(其a)还有…如果我把这个包起来,一切都很好,但是如果我把这个包起来,它会像div id=“precode”>一样把它们包起来
if(id=='style'){
                var sel=document.createElement('select'),
                styles=obj.styles||[['Style',''],['Paragraph','<p>'],['Header 1','<h1>'],['Header 2','<h2>'],['Header 3','<h3>'],['Header 4','<h4>'],['Header 5','<h5>'],['Header 6','<h6>'],['CodeBlock','<pre>']],
                sl=styles.length, x=0;
                sel.className='testyle'; sel.onchange=new Function(this.n+'.ddaction(this,"formatblock")');
                for(x;x<sl;x++){
                    var style=styles[x];
                    sel.options[x]=new Option(style[0],style[1])
                }