How to get URL parameter using jQuery or plain JavaScript?

前端 未结 30 3264
天涯浪人
天涯浪人 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:01

    If you want to find a specific parameter from a specific url:

    function findParam(url, param){
      var check = "" + param;
      if(url.search(check )>=0){
          return url.substring(url.search(check )).split('&')[0].split('=')[1];
      }
    }  
    
    var url = "http://www.yourdomain.com/example?id=1&order_no=114&invoice_no=254";  
    alert(findParam(url,"order_no"));
    

提交回复
热议问题