页面之间传值
Javascript:1、获取url地址栏中的参数:
function getParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg);//匹配目标参数
if (r != null) return decodeURI(r[2]); return null;//返回参数值
}
2、使用方法:getParam(“参数名”)
jQuery:1、获取url地址栏中的参数:
(function ($) {
$.getUrlParam = function (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return decodeURI(r[2]); return null;
}
})(jQuery);
2、使用方法:$.getUrlParam(“参数名”);
例如:前一页:window.location.href = "../html/payOrder.html?buytotal="+buytotal+"&buynum="+buynum;
当前页URL:http://192.168.0.6:8020/webapp/html/payOrder.html?buytotal=100&buynum=200
获取buytotal的值:getParam(“buytotal”) = 100 ----- $.getUrlParam(“buytotal”)
获取buynum的值:getParam(“buynum”) = 200