简单的Javascript替换不起作用 [英] Simple Javascript Replace not working
本文介绍了简单的Javascript替换不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这看起来如此简单和微不足道,但它无法正常工作。这是我的javascript:
This seems so simple and trivial but it is not working. Here is my javascript:
var url = "/computers/";
console.log(url);
url.replace(/\//gi, " ");
console.log(url);
这是我的浏览器控制台中的输出:
And here is the output in my browsers console:
/computers/
/computers/
你可以看到没有任何变化。你可以从代码中看出我试图用空格替换正斜杠。我做错了什么?
As you can see nothing changes. As you can tell from the code I'm trying to replace the forward slashes with spaces. What am I doing wrong?
推荐答案
url = url.replace(/\//gi, " ");
这篇关于简单的Javascript替换不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文