How can I add or update a query string parameter?

后端 未结 27 3194
别那么骄傲
别那么骄傲 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:25

    If it's not set or want to update with a new value you can use:

    window.location.search = 'param=value'; // or param=new_value
    

    This is in simple Javascript, by the way.

    EDIT

    You may want to try using the jquery query-object plugin

    window.location.search = jQuery.query.set("param", 5);

提交回复
热议问题