zoukankan      html  css  js  c++  java
  • JS 获取url参数

    <html>
    <body>
    
    浏览器中输入 http://localhost/test/js_url.php?a1=aaa&a2=bbb&a3=ccc
    会依次弹出aaa,bbb,ccc
    
    <script type="text/javascript">
    //方法一
    function GetQueryString(name)
    {
         var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
         var r = window.location.search.substr(1).match(reg);
         if(r!=null)return  unescape(r[2]); return null;
    }
    
    // 调用方法
    alert(GetQueryString("a1"));
    alert(GetQueryString("a2"));
    
    //方法二
    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[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }
    var Request = new Object();
    Request = GetRequest();
    alert(Request['a3']);
    
    </script>
    </body>
    </html>
  • 相关阅读:
    to_char &&to_date
    java中Integer 与 String 类型的 相互 转换
    group by 的用法
    谈 计算时间的天数差
    领域建模
    Java Classloader详解
    阿里巴巴Java招聘
    Maven Archetype
    负载均衡
    Maven
  • 原文地址:https://www.cnblogs.com/dreamhome/p/5994739.html
Copyright © 2011-2022 走看看