Updating existing URL querystring values with jQuery

前端 未结 9 860
逝去的感伤
逝去的感伤 2020-12-01 16:15

Let\'s say I have a url such as:

http://www.example.com/hello.png?w=100&h=100&bg=white

What I\'d like to do is update the values of

9条回答
  •  佛祖请我去吃肉
    2020-12-01 16:43

    URI.js seems like the best approach to me http://medialize.github.io/URI.js/

    let uri = URI("http://test.com/foo.html").addQuery("a", "b");
    // http://test.com/foo.html?a=b
    uri.addQuery("c", 22);
    // http://test.com/foo.html?a=b&c=22
    uri.hash("h1");
    // http://test.com/foo.html?a=b&c=22#h1
    uri.hash("h2");
    // http://test.com/foo.html?a=b&c=22#h2
    

提交回复
热议问题