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;
    
            }

    使用很方便,记录备用!

  • 相关阅读:
    [CF598E] Chocolate Bar
    [CF629D] Babaei and Birthday Cake
    [CF961D] Pair Of Lines
    [CF468B] Two Sets
    [CF767C] Garland
    [CF864E] Fire
    [CF578C] Weakness and Poorness
    [CF555B] Case of Fugitive
    [CF118E] Bertown roads
    [CF1301D] Time to Run
  • 原文地址:https://www.cnblogs.com/ccuc/p/5955589.html
Copyright © 2011-2022 走看看