本地儲存localstorage的使用

2021-09-29 06:39:31 字數 796 閱讀 1894

將資料儲存在本地,非記憶體,非伺服器,儲存在本地的好處,可以長時間儲存,可以不用連線伺服器,可以實現跨頁面儲存資料

localstorage:字元,5m,永久,不允許跨域(伺服器,瀏覽器),不會隨著http發給伺服器,不需要在伺服器環境下使用

localstorage是window身上的乙個子物件

console.log(window.localstorage === localstorage);

console.log(localstorage)

1.作為物件操作

localstorage.name = "admin";

localstorage.age = 18;

localstorage.name = "root";

delete localstorage.name;

console.log(localstorage.age)

2.使用專用方法操作

localstorage.setitem("a",10);

localstorage.setitem("b",20);

localstorage.setitem("a",30);

console.log(localstorage.getitem("a"))

console.log(localstorage.getitem("age"))

localstorage.removeitem("a")

localstorage.removeitem("age")

localstorage.clear()

060JS 本地儲存localStorage

doctype html en utf 8 viewport content width device width,initial scale 1.0 x ua compatible content ie edge document title head 生命週期永久生效,除非手動刪除否則關閉頁面也...

html5本地儲存Localstorage屬性

html5中,新加入了乙個localstorage特性,這個特性主要是用來作為本地儲存來使用的。並且在ie8以上的ie版本才支援localstorage這個屬性。儲存 localstorage.setitem key value 檢索 var check localstorage.getitem k...

HTML5本地儲存Localstorage的應用

localstorage可以說是對cookie的優化,使用它可以方便在客戶端儲存資料,並且不會隨著http傳輸,但也不是沒有問題 localstorage大小限制在500萬字元左右,各個瀏覽器不一致 localstorage在隱私模式下不可讀取 localstorage本質是在讀寫檔案,資料多的話會...