替换网址中的所有“ - ”

时间:2012-08-13 01:29:24

标签: javascript

我的代码现在只用空格替换第一个-,但网址中有多个-,如何用空格替换所有?{/ p>

window.location.hash.substring(1).replace('-', ' ');

1 个答案:

答案 0 :(得分:3)

尝试:

window.location.hash.substring(1).replace(/-/g, ' ')

g - >所有实例