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 needle = '/'+key+'/g'; str = str.replace(needle, trans[key]);
为此交换你的针:
var needle = new RegExp(key, "g");