2020-3-27原生JS/ZL7:原生JS页面之间的参数传递及获取

1、window.location.href=“book_chapter.htm?idx1=”+i;idx1是下一个页面接受数据的变量
window.onload = function(){
var a=GetRequest();
var jsz=a[‘i’];
console.log(jsz)
if(jsz == 2){
ybj();
}
};
// 页面传值获取传递值的方法封装
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]] = decodeURIComponent(strs[i].split("=")[1]);
}
}
return theRequest;
}

发布了11 篇原创文章 · 获赞 0 · 访问量 33

猜你喜欢

转载自blog.csdn.net/qq_25787687/article/details/105144588