<body>
<button id="btn1">设置值</button>
<button id="btn2">获取值</button>
<!--
总结:设置值 值是字符串 sessionStorage.setItem('key','value');
使用sessionStorage.getItem('key');获取值
-->
<script>
// 使用sessionStorage设置值 和使用sessionStorage获取值
// 获取dom
const btn1 = document.getElementById('btn1');
const btn2 = document.getElementById('btn2');
//注册点击事件
btn1.addEventListener('click',()=>{
//设置值 值是字符串 sessionStorage.setItem('key','value');
sessionStorage.setItem('myname','王大仙');
sessionStorage.setItem('myage','32');
sessionStorage.setItem('mysex','男');
});
//注册点击事件
btn2.addEventListener('click',()=>{
const myname = sessionStorage.getItem('myname');
const myage = sessionStorage.getItem('myage');
const mysex = sessionStorage.getItem('mysex');
console.log(myname, myage, mysex);
})