window.location.href跳转传参并接收参数
最近做H5页面之间跳转以及带有参数的传递,下边就让我们一起来练习一下吧!window.location.href = "buyOil.html?userId="+ res.userId;buyOil.html这是跳转路径的地址res.userId是我们传过去的参数,在这里我们模拟res.userId是2,所以就变成了window.location.href = "buyOil.html?userI
·
最近做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
更多推荐
已为社区贡献1条内容
所有评论(0)