使用jquery或javascript [重复]从网址中删除特定参数

问题描述 投票:0回答:1

URL是这样的

../search/days=4&people=4&stars[]=1&stars[]=2

我想删除参数star [],在我的情况下该参数是多个。我尝试使用下面的脚本,但它仅删除了1个参数实例,但不是全部。

var onlyUrl = window.location.href.replace(/&stars\[\]=\d+/, '');

简短而甜美的解决方案,不胜感激。预先谢谢你。

javascript jquery
1个回答
0
投票

您需要为全局正则表达式添加/ g

var onlyUrl = window.location.href.replace(/&stars\[\]=\d+/g, '');
© www.soinside.com 2019 - 2024. All rights reserved.