window.utils = window.utils || {};
(function(){
    'use strict';
    var STYLE_HELP_ARY = [];
    var STYLE_REG = /{(.*?)}/g;
    utils.styleString = ((str,color) => {
        var reg = STYLE_REG;
        var result = STYLE_HELP_ARY;
        result.length = 0;
        reg.lastIndex = 0;
        if(reg.test(str)){
            var d;
            while((d = reg.exec(str)) != null){
                result.push([d.index + 1, d.index + d[1].length + 1]);
            }
            var len = result.length;
            for(var i = 0; i < len; i ++){
                result[i][0] -= (1 + i * 2);
                result[i][1] -= (1 + i * 2);
            }
            result.content = str.replace(reg, "$1");
            result.htmlContent = str.replace(reg, 
                "<span style=color:" + "#" + color.toString(16) + ">" + "$1"+ "</span>");
        }
        else{
            result.content = str;
        }
        return result; //返回类型数组,数组内存储需要变色的字段起始和结束的索引,属性content为默认字符串,属性htmlContent返回的内容可以直接在诸如span元素的innerHTML属性上进行填充
    });
  }());

参考链接: https://stackoverflow.com/questions/10982489/javascript-change-font-color

var s = "a{bc}dd{e}fg"; //使用大括号进行标识需要变色的字段
var c = utils.styleString(s, 0xFF0000); //红色标识

var d = document.createElement("span");
d.innerHtml = c.htmlContent;