Search and replace specific query string parameter value in javascript

后端 未结 6 1614
无人及你
无人及你 2020-12-23 20:07

I have a string which is something like this :

a_href= \"www.google.com/test_ref=abc\";

I need to search for test_ref=abc in thisabove stri

6条回答
  •  醉酒成梦
    2020-12-23 20:54

    Based on this discussion I have created a references function. enjoy

    updateUrlParameter(url, param, value){
        var regex = new RegExp("/([?|&]" + param + "=)[^\&]+/");
        return url.replace(regex, '$1' + value);
    }
    

提交回复
热议问题