最近做H5页面之间跳转以及带有参数的传递,下边就让我们一起来练习一下吧!

window.location.href = "buyOil.html?userId="+ res.userId;
buyOil.html    这是跳转路径的地址
res.userId是我们传过去的参数,在这里我们模拟res.userId是2,所以就变成了
window.location.href = "buyOil.html?userId="+ 2;

我们在buyOil.html这里边接受这个参数

				function GetRequest() {
					var url = location.search; //获取url中"?"符后的字串
					var theRequest = new Object();
					if (url.indexOf("?") != -1) {
						var str = url.substr(1);
						strs = str.split("&");
						for (var i = 0; i < strs.length; i++) {
							theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
						}
					}
					return theRequest;
				}
				console.log(GetRequest().userId);  //2

这时候打印出来的结果就是我们传过来的参数,就是2

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐