获取URL传过来参数的值

标题获取URL传过来参数的值

  • JS方法
// 获取传过来的值
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]] = decodeURIComponent(strs[i]
					.split("=")[1]);
		}
	}
	return theRequest;
}
//调用方法
var nameVlue=getQueryString("参数名称");
  • 例子
    URL地址:https://www.baidu.com/link?url=KGIzdCCbSrLrW1JgDvkpT6SydCSBh7CC_knAj8JkG4tJe1vbPd7zamIaPrdzVw1Bd6dqLj8bI0HFGOCgWVd_iK&wd=&eqid=fcede81d0003241f000000025c1c835c
    获取wd的值:var eqid=getQueryString(“eqid”);
    结果:eqid为fcede81d0003241f000000025c1c835c;

你可能感兴趣的:(web)