关于javascript:js获取url问号后参数

40次阅读

共计 397 个字符,预计需要花费 1 分钟才能阅读完成。

// 获取 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;
}

正文完
 0