Я хочу этот код:
function renderTemplate(temp,content){
for (var i in temp){
replace = new RegExp("["+i+"]",'g');
content = content.replace(i,temp[i]);
}
return content;
}
var temp = {'status':'ok','id':150};
var content = "your status is [status], again! your status is [status], and your id is [id], yes[id]";
alert(renderTemplate(temp,content));
Для создания этой строки:
your status is ok, again! your status is ok, and your id is 150, yes 150
Вместо этого я получаю:
your ok is [status], again! your status is [status], and your 150 is [id], yes[id]
Посмотрите, где был размещен ok
....
Вы можете запустить его здесь: http://jsfiddle.net/v9vzd/
Спасибо