我有这个网址:的JavaScript replace()方法不工作
我想有这样的:
HTTP:\/\ /example.com \/example \/sample \ /example.jpg
I wrote this code :
function addslashes(str) {
return str.replace('/', '\/');
}
var url = http://example.com/example/sample/example.jpg
var t = addslashes(url);
alert(t);
作为一个提醒,我仍然得到旧的URL。这段代码有什么问题? 谢谢。
用它尝试'.replace(/ \ //克, '\\ /')' – 2014-09-10 08:21:03
测试:''\/'==='/'' – user2864740 2014-09-10 08:45:41