[英]How to add/update query string link to end of exisiting URL
盡管我嘗試使用功能鏈接來更新或添加到產品上的過濾器,但我的側邊欄上已有產品過濾器。 當前頁面的摘要
目前,我具有帶有<a href =“?filter_caster-type = swivel”>的鏈接,盡管使用該鏈接會刪除當前查詢。 有沒有一種簡單的方法可以使鏈接更新或添加到當前查詢?
如果您能夠使用URLSearchParams :
// assumes the URL already contains a query string, better checking will be needed if this isn't always the case
var paramsFromURL = new URLSearchParams(document.location.search.substring(1));
paramsFromURL.set("WhateverYouNeedToAdd", "TheValueYouWant")
// gives something like http://example.com/path/?ExistingThing=foo&WhateverYouNeedToAdd=TheValueYouWant
var updatedURL = document.location.origin + document.location.pathname + "?" + URLSearchParams.toString();
要將查詢添加到當前URL中,您可以通過javascript函數執行以下操作:
$(function(){
$('a').on('click', function(e){
e.preventDefault();
window.location.replace(window.location.href + $(this).attr('href'));
});
});
此功能把你目前的網址,並將你在你的過濾器a
標簽,然后重新裝入。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.