0

我在这里有这段代码:

<script type="text/javascript">
    var catURL = window.location.pathname;
    var catTitle = catURL.split("/");
    catTitleNew = catTitle[4].replace("-", " ");
    alert(catTitleNew);
    //this will alert will convert this-is-my-title to this is-my-title
</script>

而且我认为我的替换代码不起作用,它只是替换第一个"-"我如何让它替换所有的"-"

4

1 回答 1

4
catTitleNew = catTitle[4].replace(/-/g, " ");

小提琴

于 2013-11-14T18:53:15.903 回答