/**
* 获取指定的URL参数值 * URL:http://www.quwan.com/index?name=tyler * 参数:paramName URL参数 * 调用方法:getParam("name") * 返回值:tyler */ function getUrlParam(paramName) {
var paramValue = "", isFound = !1;
if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
}
return paramValue == "" && (paramValue = null), paramValue
}
调用时:
getUrlParam("userId");
方法二:
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[属性名]==值 组装成对象
theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]); //unescape()对通过 escape() 编码的字符串进行解码 } } return theRequest; }
调用时:GetRequest();//