通过为Jquery二次封装获取获取地址栏中的参数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/marko_zheng/article/details/83105974

通过为Jquery二次封装获取获取地址栏中的参数

需要先引入jQuery

(function ($) {
    $.getUrlParamas = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    }
})(jQuery);

当地址栏中参数不止一个的时候可通过不断调用该方法去获取
例如:
地址栏为http://xxxxxx.com/index.htm,l?one=1003&two=1014;
需要获取两个的参数的时候

alert($.getUrlParamas('one'));
 alert($.getUrlParamas('two'))

猜你喜欢

转载自blog.csdn.net/marko_zheng/article/details/83105974