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(); // 清空
需要保存的值為對象時,要將對象先轉(zhuǎn)換為String類型;可以用JSON.stringify()方法
localStorage: 沒有時間限制;sessionStorage:瀏覽器關閉后就會清空
詳解博客: http://www.cnblogs.com/st-leslie/p/5617130.html