localStorage.name = "hh"; //創(chuàng)建
localhostStroge.setItem("name", "hh"); //創(chuàng)建
localhostStroge.getItem("name", "hh"); // 獲取
localhostStroge.removetItem("name"); // 刪除
localStorage.clear(); // 清空
sessionStorage.name = "hh"; //創(chuàng)建
sessionStorage.setItem("name", "hh"); //創(chuàng)建
sessionStorage.getItem("name", "hh"); // 獲取
sessionStorage.removetItem("name"); // 刪除
sessionStorage.clear(); // 清空
需要保存的值為對(duì)象時(shí),要將對(duì)象先轉(zhuǎn)換為String類型;可以用JSON.stringify()方法
localStorage: 沒有時(shí)間限制;sessionStorage:瀏覽器關(guān)閉后就會(huì)清空
詳解博客: http://www.cnblogs.com/st-leslie/p/5617130.html