<分区>
Possible Duplicate:
replace all occurrences in a string
我的代码:
alert('111'.replace('1','2'));
它给出的结果为 211
。但我需要 222
的结果。
标签 javascript regex
<分区>
Possible Duplicate:
replace all occurrences in a string
我的代码:
alert('111'.replace('1','2'));
它给出的结果为 211
。但我需要 222
的结果。
最佳答案
为了替换所有,您可以使用regular expression使用 g
(即全局)标志:
"111".replace(/1/g, "2");
关于javascript - 用 JavaScript 替换字符串中所有出现的地方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13725739/