獲取頁面跳轉攜帶的參數


/** 

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









免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM