localStorage 与 sessionStorage

Definition and use

localStorage and data storage properties allow sessionStorage key / value pairs in the browser.

LocalStorage data for long-term preservation of data for the entire site, saved time has not expired, until manually to delete.

localStorage attribute is read-only.

localStorage only supports string type of storage

sessionStorage used to temporarily hold the same window (or tab) data, these data will be deleted after closing the window or tab.

 

localStorage is written in three ways:

IF (! window . localStorage ) { Alert ( "browser does not support localStorage" ); return to false ; } the else { var Storage = window . localStorage ; // write a field Storage [ "a" ] = . 1 ; // Write b into the field Storage . b = . 1 ; // write field c Storage . the setItem ( "c" , . 3 ); Console . log ( typeof       Storage [ "A" ]); Console . log ( typeof Storage [ "B" ]); Console . log ( typeof Storage [ "C" ]); } times following examples click the button for recording: 



1 if (sessionStorage.clickcount) {
2     sessionStorage.clickcount = Number(sessionStorage.clickcount) + 1;
3 } else {
4     sessionStorage.clickcount = 1;
5 }
6 document.getElementById("result").innerHTML = "你在按钮上已经点击了 " +
7 sessionStorage.clickcount + " 次。";

 





Guess you like

Origin www.cnblogs.com/jiehanshi/p/11646271.html