/**
* 獲取指定的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();//