zoukankan      html  css  js  c++  java
  • 获取页面跳转携带的参数

    /** 

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








  • 相关阅读:
    CCF 小明放学 201812-2(简单模拟)
    CSP 小明上学 201812-1 (水题)
    201903-4 消息传递接口(队列模拟)
    Betsy's Tour 漫游小镇(dfs)
    Checker Challenge跳棋的挑战(n皇后问题)
    Money Systems 货币系统(母函数)
    中国剩余定理(模板+详解)
    Biorhythms(中国剩余定理(模板题))
    输入输出外挂(纯数字型)
    欧几里德(转)
  • 原文地址:https://www.cnblogs.com/chenlongsheng/p/9809402.html
Copyright © 2011-2022 走看看