function getRequestParams() {
var url = location.search; //获取url中"?"符后的字串
var requestParams = new Object();
if (url.indexOf("?") != -1) { //url存在参数
var str = url.substr(1);
if (str.indexOf("&") != -1) { //url存在多个参数(至少两个参数)
strs = str.split("&");
for ( var i = 0; i < strs.length; i++) {
requestParams[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
}
} else { //url只有一个参数
requestParams[str.split("=")[0]] = decodeURI(str.split("=")[1]);
}
}
//alert(JSON.stringify(requestParams));
return requestParams;
}
Javascript解析URL传递的参数
最新推荐文章于 2023-08-14 22:18:59 发布