不知道爲什麼,但我似乎無法取代看似簡單的佔位符。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