可能重複:
Why does javascript replace only first instance when using replace?我如何能與jQuery或JavaScript替換裏面的可變文本
我有這個變量
var newRow = "<td><div> [[myvar]]</div> <div> [[myvar]]</div> </td> "
當我這樣做
newRow = newRow.replace('[[myvar]]', '10');
僅限首次出現被替換,而不是第二
請參閱[本] [1]答案。這幾乎是同一個問題。 [1]:http://stackoverflow.com/questions/1967119/why-does-javascript-replace-only-first-instance-when-using-replace – David