URL是这样的
../search/days=4&people=4&stars[]=1&stars[]=2
我想删除参数star [],在我的情况下该参数是多个。我尝试使用下面的脚本,但它仅删除了1个参数实例,但不是全部。
var onlyUrl = window.location.href.replace(/&stars\[\]=\d+/, '');
简短而甜美的解决方案,不胜感激。预先谢谢你。
您需要为全局正则表达式添加/ g
var onlyUrl = window.location.href.replace(/&stars\[\]=\d+/g, '');