javascript replace()不会替换所有匹配的字符 [英] javascript replace() is not replacing all the characters match
本文介绍了javascript replace()不会替换所有匹配的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 replace()将/Admin/ListOfMovies 转换为 _Admin_ListOfMovies .
var $id = id.replace('/', '_');
看起来它只替换了第一个/.如何替换所有这些?
It looks like it only replacing the first /. How do I replace all of them?
感谢您的帮助.
推荐答案
Use a regex with the g
flag.
var $id = id.replace(/\//g, '_');
这篇关于javascript replace()不会替换所有匹配的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文