html页面之间传递参数

方法:HTML5本地存储,即在A页面存储数据,然后在B页面获取
localStorage存储的数据,localStorage 方法存储的数据没有时间限制。第二天、第二周或下一年之后,数据依然可用。
http://www.w3school.com.cn/html5/html_5_webstorage.asp
//A页面
方法一:
// Check browser support
if (typeof(Storage) !== "undefined") {
// Store
localStorage.setItem("lastname", "Gates");
// Retrieve
document.getElementById("test").innerHTML = localStorage.getItem("lastname");
} else {
document.getElementById("test").innerHTML = "抱歉!您的浏览器不支持 Web Storage ...";
}
方法二:
localStorage['foo'] = 'newBar';
方法三:
sessionStorage.setItem('testKey','这是一个测试的value值'); // 存入一个值
//B页面
方法一:
document.getElementById("a-test").innerHTML = localStorage.getItem("lastname");
方法二:
localStorage["foo"]
方法三:
console.log(sessionStorage.getItem('testKey')); // => 返回testKey对应的值); 关闭浏览器后再打开,数据会被删除,所以控制台输出的null,需要重新打开A页面,再刷新B页面,控制台输出这是一个测试的value值
输出结果:
console.log(localStorage.getItem("foo")); //newBar
console.log(localStorage["foo"]); //谷歌浏览器:newBar 360、IE浏览器:null

你可能感兴趣的:(html页面之间传递参数)