How can I add or update a query string parameter?

后端 未结 27 2883
别那么骄傲
别那么骄傲 2020-11-22 02:35

With javascript how can I add a query string parameter to the url if not present or if it present, update the current value? I am using jquery for my client side development

27条回答
  •  失恋的感觉
    2020-11-22 03:08

    By using jQuery we can do like below

    var query_object = $.query_string;
    query_object["KEY"] = "VALUE";
    var new_url = window.location.pathname + '?'+$.param(query_object)
    

    In variable new_url we will have new query parameters.

    Reference: http://api.jquery.com/jquery.param/

提交回复
热议问题