How to create a "bbcode" javascript with replace

This question already has an answer here:

  • How to replace all occurrences of a string in JavaScript? 41 answers

  • Try

    postText.html(postText
                  .html()
                  .replace(/[tag]/g,'<span class="tag">')
                  .replace(/[/tag]/g,'</span>')
                  );
    

    Ex:

    $('.post').html(function(){
        return $(this)
        .html()
        .replace(/[tag]/g,'<span class="tag">')
        .replace(/[/tag]/g,'</span>')
    })
    

    Demo: Fiddle

    链接地址: http://www.djcxy.com/p/16848.html

    上一篇: 从字符串中多次删除字符

    下一篇: 如何用replace替换创建一个“bbcode”javascript