js获取url问号后参数

//获取url
console.log(window.location.search)
var urlParams = new Object();
urlParams = this.getParams();
this.id = urlParams['id'];
this.name = urlParams['name'];
console.log(id, name)

getParams() {
  var url = location.search;
  var params = new Object();
  if (url.indexOf("?") != -1) {
    var str = url.substr(1);
    strs = str.split("&");
    for (var i = 0; i < strs.length; i++) {
      params[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
    }
  }
  return params;
}

你可能感兴趣的:(javascript前端)