Dario,因爲您使用的是LocalStorage
,所以不需要插件。我不知道你的語句:
window.localStorage.key(i);
哪裏是i
集?
我有一個與Getter/Setter一起使用的UTIL類。這是js
。希望這可以幫助。
var util = function() {
return {
//-----------------------------------
set: function (key, value) {
localStorage.setItem(key, JSON.stringify(value));
},
//-----------------------------------
get: function (key, defaultVal) {
var value = JSON.parse(localStorage.getItem(key));
if (value === null) value = defaultVal;
return value;
},
}; //End Return
}(); //End Closure
//Sample Set
util.set("downloadFlag", 1);
//Sample Get (with a default value 0 if null is found)
var fileDownloadedFlag = util.get("downloadFlag", 0);