获取URL参数JS函数

//获取URL参数
function getUrlParam(paramName) {
var href = window.location.href;
var url = decodeURI(href);
var idx = url.indexOf("?");
var params = url.substring(idx + 1);
if (params) {
params = params.split("&");
for (var i = 0; i < params.length; i += 1) {
var param = params[i].split("=");
if (param[0] == paramName) {
//完善获取url参数的逻辑
var pArr = [];
for (var k = 1, len = param.length; k < len; k++) {
pArr.push(param[k]);
}
var p = pArr.join('=');
var idx1 = p.indexOf("#");
if (idx1 != -1) {
p = p.substring(0, idx1);
}
return p;
}
}
}
};

posted on 2019-05-22 10:11  只为_更加优秀!  阅读(553)  评论(0编辑  收藏  举报

导航