替换字符串javascript中的多个文本

替换字符串javascript中的多个文本,javascript,jquery,Javascript,Jquery,您好,我正在尝试用图像替换所选单词的列表。。。。所以我尝试了下面的代码 function replaceTextWithEmoticon(text) { return text.replace("[[happybirthday]]","<img src='smileys/birthday.gif' style='height:17px;margin-top:1px;'/>"); return text.replace(":s","<img src='smiley

您好,我正在尝试用图像替换所选单词的列表。。。。所以我尝试了下面的代码

function replaceTextWithEmoticon(text)
{


return text.replace("[[happybirthday]]","<img src='smileys/birthday.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace(":s","<img src='smileys/blue.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace(":%","<img src='smileys/blush.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[boo]]","<img src='smileys/boo.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace(":>","<img src='smileys/book.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[busted]]","<img src='smileys/busted.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace(":*:)","<img src='smileys/cheekkiss.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[goodnight]]","<img src='smileys/goodnight.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[newhere]]","<img src='smileys/newhere.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[nicethread]]","<img src='smileys/nicethread.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[nospam]]","<img src='smileys/nospamhere.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[offtopic]]","<img src='smileys/offtopic.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("0:)","<img src='smileys/smiley-angelic002.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("^^'","<img src='smileys/smiley-ashamed004.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("E:|","<img src='smileys/smiley-confused001.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[:|","<img src='smileys/smiley-confused002.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("v:(v","<img src='smileys/smiley-confused005.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("v0v","<img src='smileys/smiley-confused013.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("B)","<img src='smileys/smiley-cool02.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[dancewithpartner]]","<img src='smileys/smiley-dance012.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[buttdance]]","<img src='smileys/smiley-dance019.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("3:)","<img src='smileys/smiley-devil03.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[excited]]","<img src='smileys/smiley-excited001.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[fartsingle]]","<img src='smileys/smiley-fart004.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[fartdouble]]","<img src='smileys/smiley-fart005.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[midfing]]","<img src='smileys/smiley-finger005.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[cheerleader]]","<img src='smileys/smiley-gen013.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[bgfight]]","<img src='smileys/smiley-gen041.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[score]]","<img src='smileys/smiley-gen055.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[thumbdown]]","<img src='smileys/smiley-gen073.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[musichappy]]","<img src='smileys/smiley-happy011.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[wave]]","<img src='smileys/smiley-happy020.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace(";)","<img src='smileys/smiley-happy112.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace(":)","<img src='smileys/smiley-happy119.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[brushnails]]","<img src='smileys/smiley-happy120.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[backhug]]","<img src='smileys/smiley-hug001.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[friendshi5]]","<img src='smileys/smiley-hug004.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[makehappy]]","<img src='smileys/smiley-hug005.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[bfgfhug]]","<img src='smileys/smiley-hug006.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[lovehug]]","<img src='smileys/smiley-hug014.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[naughty]]","<img src='smileys/smiley-hug015.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[laughhard]]","<img src='smileys/smiley-laughing001.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[laughnormal]]","<img src='smileys/smiley-laughing002.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[iluvu]]","<img src='smileys/smiley-love001.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[kisshand]]","<img src='smileys/smiley-love007.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[coupleluv]]","<img src='smileys/smiley-love010.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[cheekkiss]]","<img src='smileys/smiley-love011.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("<3","<img src='smileys/smiley-love018.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[candlelightdinner]]","<img src='smileys/smiley-love019.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[intenseluv]]","<img src='smileys/smiley-love022.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[merrygoround]]","<img src='smileys/smiley-love025.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[toiletplungerkiss]]","<img src='smileys/smiley-love027.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[kissinglips]]","<img src='smileys/smiley-love028.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace(":(","<img src='smileys/smiley-sad056.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace(":P","<img src='smileys/smiley-taunt002.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace(":p","<img src='smileys/smiley-taunt002.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace(":P|","<img src='smileys/smiley-taunt014.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace(":p|","<img src='smileys/smiley-taunt014.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[welcome]]","<img src='smileys/welcome.gif' style='height:17px;margin-top:1px;'/>");
      return text.replace("[[wtf]]","<img src='smileys/wtf.gif' style='height:17px;margin-top:1px;'/>");


}
function replaceTextWithEmoticon(文本)
{
返回文本。替换(“[[happybirthday]]”,“”);
返回文本。替换(“:s”,”);
返回文本。替换(“:%”,“”);
返回文本。替换(“[[boo]]”,“”);
返回文本。替换(“:>”,“”);
返回文本。替换(“[[busted]]”,“”);
返回文本。替换(“:*:)”,“”);
返回文本。替换(“[[晚安]]”,“”);
返回文本。替换(“[[newhere]]”,“”);
返回文本。替换(“[[nicethread]]”,“”);
返回文本。替换(“[[nospam]]”,“”);
返回文本。替换(“[[offtopic]]”,“”);
返回文本。替换(“0:)”,“”);
返回文本。替换(“^^””);
返回文本。替换(“E:|”和“”);
返回文本。替换(“[:;”,“”);
返回文本。替换(“v:,v”);
返回文本。替换(“v0v”和“”);
返回文本。替换(“B)”,“”);
返回文本。替换(“[[dancewithpartner]]”,“”);
返回文本。替换(“[[buttdance]]”,“”);
返回文本。替换(“3:)”,“”);
返回文本。替换(“[[Exceeted]]”,“”);
返回文本。替换(“[[fartsingle]]”,“”);
返回文本。替换(“[[fartdouble]]”,“”);
返回文本。替换(“[[midfing]]”,“”);
返回文本。替换(“[[Cheerreader]]”,“”);
返回文本。替换(“[[bgfait]]”,“”);
返回文本。替换(“[[score]]”,“”);
返回文本。替换(“[[thumbdown]]”,“”);
返回文本。替换(“[[musichappy]]”,“”);
返回文本。替换(“[[wave]]”,“”);
返回文本。替换(“;)”,“”);
返回文本。替换(“:)”,“”);
返回文本。替换(“[[Brush钉子]]”,“”);
返回文本。替换(“[[backhug]]”,“”);
返回文本。替换(“[[friendshi5]]”,“”);
返回文本。替换(“[[makehappy]]”,“”);
返回文本。替换(“[[bfgfhug]]”,“”);
返回文本。替换(“[[lovehug]]”,“”);
返回文本。替换(“[[淘气]]”,替换“);
返回文本。替换(“[[laughthard]]”,“”);
返回文本。替换(“[[laughtnormal]]”,“”);
返回文本。替换(“[[iluvu]]”,“”);
返回文本。替换(“[[kisshand]]”,“”);
返回文本。替换(“[[coupleluv]]”,“”);
返回文本。替换(“[[cheekkiss]]”,“”);

return text.replace(“
return
表示将不执行它下面的任何内容。相反,您应该将它分配给一个变量并返回

function replaceTextWithEmoticon(text)
{

  text = text.replace(/\[\[happybirthday\]\]/g,"<img src='smileys/birthday.gif' style='height:17px;margin-top:1px;'/>");
  text = text.replace(/:s/g,"<img src='smileys/blue.gif' style='height:17px;margin-top:1px;'/>");
  text = text.replace(/\[\[wtf\]\]/g,"<img src='smileys/wtf.gif' style='height:17px;margin-top:1px;'/>");

  ...
  return text;

}
function replaceTextWithEmoticon(文本)
{
text=text.replace(/\[\[happybirthday\]\]/g,”);
text=text.替换(/:s/g,“”);
text=text.replace(/\[\[wtf\]\]/g,”);
...
返回文本;
}
编辑
默认情况下,“替换”将只替换第一个匹配项,以替换您在正则表达式上必须使用的所有全局标志。请参阅“更新”

return
,这意味着将执行它下面的任何内容。相反,您应该将其分配给一个变量并返回该值

function replaceTextWithEmoticon(text)
{

  text = text.replace(/\[\[happybirthday\]\]/g,"<img src='smileys/birthday.gif' style='height:17px;margin-top:1px;'/>");
  text = text.replace(/:s/g,"<img src='smileys/blue.gif' style='height:17px;margin-top:1px;'/>");
  text = text.replace(/\[\[wtf\]\]/g,"<img src='smileys/wtf.gif' style='height:17px;margin-top:1px;'/>");

  ...
  return text;

}
function replaceTextWithEmoticon(文本)
{
text=text.replace(/\[\[happybirthday\]\]/g,”);
text=text.替换(/:s/g,“”);
text=text.replace(/\[\[wtf\]\]/g,”);
...
返回文本;
}
编辑
默认情况下,“替换”将只替换第一个匹配项,以替换您在正则表达式上必须使用的所有全局标志。请参阅更新。他应该逐个调用它们,并以一个字符串与之联系,然后返回

他应该逐个调用它们,以一个字符串与之联系,然后返回

假设我有一个字符串“[[wtf]]更多文本[[wtf]]“它只替换了第一个[[wtf]]而不是第二个…我该怎么做…?:)假设我有一个字符串“[[wtf]]更多的文本[[wtf]]”,它只替换了第一个[[wtf]]而不是第二个…我该怎么做…?:)