Web storage,
Localstorage
Sessionstorage:
1 檢測瀏覽器是否支持?jǐn)?shù)據(jù)存儲
注意:在html5中 使用javascript 來存儲和訪問數(shù)據(jù)的。
2. Localstorage 設(shè)置 /獲取數(shù)據(jù)
存儲在客戶端的(移動端 手機 平板…) 沒有時間限制的
常用方法:
賦值:
window.localStorage .setItem(“變量名稱”,”val”) ---》localStorage.變量名稱 = 值
取值:
window.localStorage.getItem(“變量名稱”)-à localStorage.變量名稱
注意:測試localStorage 需要到 php環(huán)境下測試
3.sessionstorage 設(shè)置/獲取數(shù)據(jù)
存儲在服務(wù)器端(sohu 美食天下)
賦值:
window. sessionStorage .setItem(“變量名稱”,”val”) ---》sessionStorage .變量名稱 = 值
取值:
window. sessionStorage .getItem(“變量名稱”)-à sessionStorage .變量名稱 sessionStorage:
關(guān)閉瀏覽器
調(diào)用:sessionStorage.removeItem(“bName”); 清空數(shù)據(jù)
案列代碼:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>無標(biāo)題文檔</title> <link rel="stylesheet" href="css/style.css"> </head> <script type="text/javascript"> //window.localStorage /sessionStorage //if(true) true 不空 0 0.0 “0” window.localStorage 有值 if(window.localStorage){ alert(111); } if(window.sessionStorage){ alert(222); } </script> <body> </body> </html>
相信看了這些案例你已經(jīng)掌握了方法,更多精彩請關(guān)注Gxl網(wǎng)其它相關(guān)文章!
相關(guān)閱讀:
CSS的文本字體顏色如何設(shè)置
Css3中hover動畫的顏色動畫怎么使用
CSS里的盒子模型的種類區(qū)別
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com