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

    使用很方便,记录备用!

  • 相关阅读:
    Stream 和 byte[] 之间的转换
    C# Process类_进程_应用程序域与上下文之间的关系
    C# Process类_进程管理器Demo
    C# attribute_特性
    SqlDataAdapter类
    SqlDataReader类
    SqlCommand类
    SqlConnection类
    DataTable类
    C# 语法技巧_三目运算_switch_case
  • 原文地址:https://www.cnblogs.com/ccuc/p/5955589.html
Copyright © 2020-2023  润新知