How to get URL parameter using jQuery or plain JavaScript?

前端 未结 30 3753
天涯浪人
天涯浪人 2020-11-21 06:29

I have seen lots of jQuery examples where parameter size and name are unknown.

My URL is only going to ever have 1 string:

http://example.com?sent=ye         


        
30条回答
  •  孤街浪徒
    2020-11-21 07:03

    I use this and it works. http://codesheet.org/codesheet/NF246Tzs

    function getUrlVars() {
        var vars = {};
        var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
        });
    return vars;
    }
    
    
    var first = getUrlVars()["id"];
    

提交回复
热议问题