不知道为什么,但我似乎无法取代看似简单的占位符。JavaScript - 字符串替换
我的做法
var content = 'This is my multi line content with a few {PLACEHOLDER} and so on';
content.replace(/{PLACEHOLDER}/, 'something');
console.log(content); // This is multi line content with a few {PLACEHOLDER} and so on
任何想法,为什么它不工作?
在此先感谢!
增加 '' 围绕{}占位符:-)你需要存储的地方替换的结果 – 2011-02-07 10:54:40
:试试这个:`var content ='this is {placeholder}'; content = content.replace(/ {placeholder} /,'something');警报(内容); ` 应该工作 – Shrinath 2011-02-07 11:01:56