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;

     

     

  • 相关阅读:
    递归
    高等数学思维导图——1.函数与极限
    sort方法和自定义比较器的写法
    PriorityQueue(优先队列)
    常用JAVA API :HashSet 和 TreeSet
    常用Java API:HashMap 和 TreeMap
    ArrayList、Vector和LinkedList的区别
    构造方法
    面向对象特点:封装、继承、多态
    匿名对象
  • 原文地址:https://www.cnblogs.com/caiCheryl/p/5666644.html
Copyright © 2011-2022 走看看