JS - get URL parameters

Regular expression to get the specified parameter

function getUrlParam(name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
  var r = window.location.search.substr(1).match(reg);  //匹配目标参数
  if (r != null) return decodeURI(r[2]); return null; //返回参数值
}

Regular expression to get the specified parameter

function getRequest() {  
  var url = location.search; //获取url中"?"符后的字串  
  var theRequest = new Object();  
  if (url.indexOf("?") != -1) {  
    var str = url.substr(1);  
    strs = str.split("&");  
    for(var i = 0; i < strs.length; i ++) {
      theRequest[strs[i].split("=")[0]]=decodeURI(strs[i].split("=")[1]);  
    }  
  }
  return theRequest;  
}

Notice

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325891783&siteId=291194637