Using location.search to locate a parameter's value

前端 未结 4 1623
走了就别回头了
走了就别回头了 2021-02-09 16:05

I’m working on a tool which takes the value parameters in the URL and does a few things with them.

My issue is, I can’t seem to use document.location to show the specifi

4条回答
  •  不要未来只要你来
    2021-02-09 16:49

    A more generic solution to split the location.search query parameters and convert them into an object:

    var a = location.search.split("&");
    var o = a.reduce(function(o, v) {
        var kv = v.split("=");
        kv[0] = kv[0].replace("?", "");
        o[kv[0]] = kv[1];
        return o;
        },
    {});
    

提交回复
热议问题