Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在无法弄清楚它如何独自工作之后,我无法举出任何例子。
我要做的就是获取一个已分配给值的字符串,并将其用作所有匹配项的替换匹配字符串。
var replacement = 'i'; var text = 'tieiam'; text = text.replace(replacement, ''); // 'teiam' text = text.replace(/tieiam/g, ''); // 'team'
我如何一起使用它们?
你想要的是使用 RegExp 对象:
text = text.replace(new RegExp(replacement, 'g'), '');
一个简单的例子。