可以通过方法将所需的用户数据存储在本地,分为临时存储和永久存储
localStorage setItem()将数据存起来 //为字符串类型
localStoragegetItem()获取本地存储数据 //为字符串类型
document.getElementsByTagName('button')[0].onclick = function() {
localStorage.setItem('sName', '王五')
localStorage.setItem('age', 20)
localStorage.setItem('arr', [10, 20, 30])
localStorage.setItem('arr', {
name: "狗蛋",
age: 55
})
var v = localStorage.getItem("sName")//获取
console.log(v);
var ar = localStorage.getItem('arr')
console.log(ar);
localStorage.removeItem('age')//删除一个
localStorage.clear();//删除所有本地存储
sessionStorage.setItem("addr", "天河路")
// sessionStorage.setItem("addr","惠济区")
var ad = sessionStorage.getItem("addr")
console.log(ad);
};