zoukankan      html  css  js  c++  java
  • getUrlParam获取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;
        }
    

      

    正则表达式获取地址栏参数

     var getParam = function (name) {
            var search = document.location.search;
            //alert(search);
            var pattern = new RegExp("[?&]" + name + "=([^&]+)", "g");
            var matcher = pattern.exec(search);
            var items = null;
            if (null != matcher) {
                try {
                    items = decodeURIComponent(decodeURIComponent(matcher[1]));
                } catch (e) {
                    try {
                        items = decodeURIComponent(matcher[1]);
                    } catch (e) {
                        items = matcher[1];
                    }
                }
            }
            return items;
        };


    way2

    getRequestParams: function () {
      var url = window.location.href;
      var theRequest = {};
      if (url.indexOf("?") > -1) {
        var currentPaths = url.split("?");
        url = _.first(currentPaths);
        var paramData_str = currentPaths[1];
        var paramData_strs = paramData_str.split("&");
        _.forEach(paramData_strs, function (n) {
          _.set(theRequest, n.split("=")[0], decodeURI(n.split("=")[1]));
        });
      }
      return theRequest;
    },
    var regist = tools.getRequestParams().regist;

     

     

  • 相关阅读:
    C#生成唯一码方法
    解剖常用软件程序都用什么语言开发
    Unity3D笔记七 GUILayout
    函数的递归
    函数
    函数的参数
    函数的返回值
    函数的定义
    文件处理
    集合
  • 原文地址:https://www.cnblogs.com/caiCheryl/p/5666644.html
Copyright © 2011-2022 走看看