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();//








  • 相关阅读:
    移动端rem适配
    extern 关键字
    腾讯2014校园招聘软件开发类笔试试题
    堆,栈,堆栈
    转:对TCP/IP网络协议的深入浅出归纳
    转:程序员面试笔试宝典学习记录(一)
    求素数
    [C++]访问控制与继承(public,protect,private) 有时间再整理!!!
    面向对象的static关键字(类中的static关键字)
    腾讯校园招聘会笔试题2011.10.15
  • 原文地址:https://www.cnblogs.com/chenlongsheng/p/9809402.html
Copyright © 2011-2022 走看看