我有一个字符串
var DisplayString = "I am having VAR_1 value in box, i have to change to VAR_2, then to VAR_3, then to VAR_4";
我需要进行循环,其中VAR_将被NEW_VAR_替换,其中数字保持不变。
我怎么能在jQuery中做到这一点?
答案 0 :(得分:0)
尝试:
var DisplayString = "I am having VAR_1 value in box, i have to change to VAR_2, then to VAR_3, then to VAR_4";
DisplayString = DisplayString.replace(/\VAR_/g, 'NEW_VAR_'); // this will replace all occurances of VAR_ to NEW_VAR_
alert(DisplayString);