history.pushState() change query values

后端 未结 3 1989
一个人的身影
一个人的身影 2020-12-10 15:01

If I have a link that is being changed with the function history.pushState({}, \"\", link); where my link is for example page.php?value=1&

3条回答
  •  [愿得一人]
    2020-12-10 15:36

    You can use this useful function to change a query string parameter value:

    function updateParam(url, param, value)
    {  
        var re = new RegExp(param+"(.+?)(&|$)","g");
    
        return url.replace(re, param+'='+value)  
    }
    

提交回复
热议问题