使用JavaScript在另一个字符串的多个位置插入字符串

时间:2015-10-14 09:18:48

标签: javascript jquery

我有2个vars,需要将b插入到evry“}”之后,并且需要任何css类。我怎么能用jquery或javascript做到这一点?

var a        = "p{font-size:20px}
                .tihais {font-weight:bold}";
var b        = "#afnay";
var position = after evry "}";

THX

2 个答案:

答案 0 :(得分:1)

var a        = "p{font-size:20px}
            .tihais {font-weight:bold}";
var b        = "}#afnay"; // This variable value is changed!
a= a.replace("}", b);

答案 1 :(得分:0)



var a = 'p{font-size:20px}\n'+
'.tihais {font-weight:bold}';
var b = "}#afnay";    
a= a.replace(/}/g, b);
console.log(a)