📌  相关文章
📜  javascript 将更新查询参数添加到 url - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:26.044000             🧑  作者: Mango

代码示例1
function update_query_parameters(key, val) {
   uri = window.location.href
      .replace(RegExp("([?&]"+key+"(?=[=&#]|$)[^#&]*|(?=#|$))"), "&"+key+"="+encodeURIComponent(val))
      .replace(/^([^?&]+)&/, "$1?");
   return uri;
}
// examples: the following may update ?page=4 in url and redirects to 
window.location.href = update_query_parameters('page', '4);