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;

     

     

  • 相关阅读:
    js中Frame框架的属性获取(1)
    c#中文件上传(1)
    表单验证Validform
    Mybatis语法笔记
    js的checkbox
    调用微信Js-SDK支付
    调用微信Js-SDK图片
    java后台上传到linux
    web服务器内层溢出
    SpringMVC
  • 原文地址:https://www.cnblogs.com/caiCheryl/p/5666644.html
Copyright © 2011-2022 走看看