使用带有颤振的 js 全局文本替换代码

我之前已经映射了JavaScript全局文本替换代码行(超过100行),如以下示例所示。很难再次映射它们以与颤振兼容。

res = str.replace(/blue/g, "red");
res = str.replace(/black/g, "white");
res = str.replace(/green/g, "yellow");
.
.
.

我想在颤动应用程序中使用此映射来替换输入文本,我是颤动的新手。有什么方法或技巧,我可以使用与thittext替换机制.


UYOU
浏览 84回答 1
1回答

慕莱坞森

使用替换全部方法,它将匹配的所有子字符串替换为替换。var res; res = str.replaceAll('blue', 'red'); res = str.replaceAll('black', 'white'); res = str.replaceAll('green', 'yellow'); ...
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript