localStorage的設定和取值Demo

2021-08-10 17:34:09 字數 1373 閱讀 2328

###localstorage的設定和取值demo

/*--------------------------- 樣例一    字串的簡單快取和獲取及移除    ------------------------*/

localstorage.setitem("test","詳情請看控制台localstorage內容變化,此物件2s後自動移除"); //快取內容方法

alert("確認檢視快取內容");

alert("快取內容: "+localstorage.getitem("test")); //獲取快取內容方法

settimeout(function(),2000);

/*--------------------------- 樣例二 字串的簡單快取和獲取及移除 -------------------------------*/

localstorage.setitem("test01","3s後可確認移除該物件");//快取內容方法

console.log(localstorage.getitem("test01")); //獲取快取內容方法

settimeout(function(),3000)

; /*--------------------------- 樣例二 --物件是快取與獲取 -------------------------------*/

var data = new object(),contarray=[1,2,3,4],contarrays=["a","b","c","d"];

data.name ="canvasdraw";

data.dataarray=contarray;

data.dataarrays=contarrays;

var str = json.stringify(data); 方法用於把乙個物件解析成乙個字串。例:var a = ;json.stringify(a) 後變為 ""

localstorage.setitem(data.name, str);

console.log(localstorage.getitem(data.name)); //獲取快取內容方法

console.log("------------",localstorage.getitem(data.name));

console.log("------------",json.parse(localstorage.getitem(data.name))); 方法用於把乙個字串解析成乙個物件。例:var b = "";json.stringify(b) 後變為

console.log("------------",json.parse(localstorage.getitem(data.name)).dataarray);

localStorage時效設定

css box contentk contentk div contentk input contentk input webkit input placeholder aging aging div nth child 2 label btn,btn1 html class box class c...

獲取和設定localStorage

東鈿金融服務平台 使用者第一次訪問頁面出現,引導步驟,起初一直使用cookie,但是cookie一直不穩定 簡單介紹和使用了localstorage 在我的頁面上就只是用了 獲取localstorage,和設定localstorage。思路和邏輯 和cookie是一樣的,如下 var a local...

localStorage設定過期時間

劃重點 sessionstorage不能跨tab頁 設定過期時間在原有的原生api基礎上封裝,存在key的過期資料 眾所周知,前端三大快取,cookie,sessionstorage,localstorage,cookie空間太小,一旦大了,會消耗流量,只適合存一些登入會話資訊,而sessionst...