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');
历经苦难而不厌,此乃阿修罗之道。
原文地址:https://www.cnblogs.com/echo1314/p/10256989.html