js 取得网址问号后面的参数(get 参数)
function getData() {
//处理get参数----------------------------
var strUrl = window.location.toString();
var getPara, ParaVal;
var aryPara = [];
if (strUrl.indexOf("?") != -1) {
var getSearch = strUrl.split("?");
getPara = getSearch[getSearch.length - 1].split("&");
for (var i = 0; i < getPara.length; i++) {
ParaVal = getPara[i].split("=");
aryPara[ParaVal[0]] = ParaVal[1];
}
}
//处理get参数 end------------------------
return aryPara;
}
getData会回传阵列方式的参数回来
https://qyweqwe.com?a=123
var GET = getData();
console.log(GET['a']); //log会印出123
留言
張貼留言