简单的 Javascript 替换不起作用 [英] Simple Javascript Replace not working

查看:32
本文介绍了简单的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆