zoukankan      html  css  js  c++  java
  • Jquery获取url中的参数

            //获取url中的参数
            function getUrlParam(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");       //构造一个含有目标参数的正则表达式对象
                var r = window.location.search.substr(1).match(reg);  //匹配目标参数
                if (r != null) return unescape(r[2]); return null; //返回参数值
            };
    
            //
            getUrlParam("update_id");

     // 添加 或者 修改 url中参数的值
            function UpdateUrlParam(name, val) {
                var thisURL = document.location.href;
                // 如果 url中包含这个参数 则修改
                if (thisURL.indexOf(name) > 0) {
                    var v = getUrlParam(name);
                    if (v != null) {
    
                        // 是否包含参数
                        thisURL = thisURL.replace(name + '=' + v, name + '=' + val);
    
                    }
                    else {
                        thisURL = thisURL.replace(name + '=', name + '=' + val);
                    }
                    
                } // 不包含这个参数 则添加
                else {
                    if (thisURL.indexOf("?") > 0) {
                        thisURL = thisURL + "&" + name + "=" + val;
                    }
                    else {
                        thisURL = thisURL + "?" + name + "=" + val;
                    }
                }
                location.href = thisURL;
    
            }

    使用很方便,记录备用!

  • 相关阅读:
    POJ1112 Team Them Up!
    WebSocket相关介绍
    长轮询 & 短轮询
    图片上传 & 预览
    sessionStorage & localStorage & cookie & session
    进程 & 线程
    https介绍与讲解
    http请求
    TCP/IP的连接与断开
    浏览器缓存
  • 原文地址:https://www.cnblogs.com/ccuc/p/5955589.html
Copyright © 2011-2022 走看看