js-获取url中传递的参数

1 (function ($) {
2         $.getUrlParam = function (name) {
3             var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
4             var r = window.location.search.substr(1).match(reg);
5             if (r != null) return decodeURIComponent(r[2]);
6             return null;
7         }
8     })(jQuery);

栗子:window.location.href="price.jsp?total="+sum+"&deviceId="+deviceId;

 

total = $.getUrlParam('total');
deviceId = $.getUrlParam('deviceId');

 

posted @ 2019-01-11 20:03  echo314  阅读(147)  评论(0编辑  收藏  举报