訪問資料localstorage

2021-08-27 20:56:39 字數 466 閱讀 3889

存:               localstorage.setitem('*****msg',json.stringify(this.resourcelists));

localstorage.setitem('chosedresourceids',json.stringify(this.chosedids));

取:     var msg=localstorage.getitem('*****msg');

var ids=localstorage.getitem('chosedresourceids');

if(msg)

localstorage/sessionstorage預設只能儲存字串,

而實際開發中,我們往往需要儲存的資料多為物件型別

,那麼這裡我們就可以在儲存時利用json.stringify()將物件轉為字串,

而在取快取時,只需配合json.parse()轉回物件即可。

html之間傳值之localStorage

b.html在需要儲存資料頁面用localstorage設定資料 localstorage.setitem key,value key要用單引號或者雙引號包括著,value就是你要存的資料在需要引用資料的頁面用localstorage獲取資料 var name localstorage.getite...

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...