您好,登錄后才能下訂單哦!
<!DOCTYPE html> <html> <body> <script> // validate thether this browser support storage if(window.localStorage){ console.log("support local storage"); } if(window.sessionStorage){ console.log("support session storage"); } addEntryForSessionStorage(); addEntryForLocalStorage(); printAllLocalStoreInfo(); printAllSessionStoreInfo(); /* ============================== session storage ============================== */ function addEntryForSessionStorage(){ var key = window.sessionStorage.length+1; var value = parseInt(Math.random()*1000); window.sessionStorage.setItem(key,value); } function printAllSessionStoreInfo(){ console.log("all session storage informaton is below."); var sessionStorage = window.sessionStorage; for(var i=0;i<sessionStorage.length;i++){ var key = sessionStorage.key(i); var value = sessionStorage.getItem(key); console.log(key+":"+value); } } /* ============================== local storage ============================== */ function addEntryForLocalStorage(){ var key = window.localStorage.length+1; var value = parseInt(Math.random()*1000); window.localStorage.setItem(key,value); } function printAllLocalStoreInfo(){ console.log("all local storage informaton is below."); var localStorage = window.localStorage; for(var i=0;i<localStorage.length;i++){ var key = localStorage.key(i); var value = localStorage.getItem(key); console.log(key+":"+value); } } </script> </body> </html>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。