我有一个可以工作的代码,但问题是它只是附加了参数。
下面是我的工作代码,而不是用新的参数替换它:
jQuery('#input_1_11').change(function(){
var type = jQuery('#input_1_11').val();
if(type=='Inspection'){
window.location.replace(window.location.href + "?Inspection");
}
else if(type=='Installation'){
window.location.replace(window.location.href + "?Installation");
}
else{
window.location.replace(window.location.href + "?Maintenance");
}
}); 例如,目前正在发生的情况
www.test.com?Inspection 然后,如果我再次单击input11,它将转到链接
www.test.com?Inspection?Maintenance我需要的是替换每个?参数,每个更改的用户。
发布于 2020-12-14 09:16:34
使用原点
window.location.origin + "?Maintenance"而不是window.location.href + "?Maintenance"
发布于 2020-12-14 09:12:15
您可以做一件事-获取当前url并将其拆分为一个数组,其中?作为split的参数。获取数组的第一个元素。它将是没有参数的url。
jQuery('#input_1_11').change(function(){
var type = jQuery('#input_1_11').val();
var present = window.location.href.split("?");
if(type=='Inspection'){
window.location.replace(present[0] + "?Inspection");
}
else if(type=='Installation'){
window.location.replace(present[0] + "?Installation");
}
else{
window.location.replace(present[0] + "?Maintenance");
}
});https://stackoverflow.com/questions/65286192
复制相似问题