【发布时间】:2015-04-28 05:33:45
【问题描述】:
我是 javascript、html5 和 jquery 的初学者,我正在尝试在我正在设计的应用程序中首次使用语言环境存储。但是,一旦我将“getIncomeArray”函数添加到我的代码中,本地存储将在我刷新后被删除...... fiddle
function getIncomeArray(){
//get or create storage arrays
var incomeArray = localStorage.getItem["incomeArray"];
console.log(incomeArray);
if (!incomeArray) {
incomeArray = [];
localStorage.setItem("incomeArray", JSON.stringify(incomeArray));
//code
console.log("there is no array so I made one");
}
else{
incomeArray = JSON.parse(incomeArray);
console.log("there is an array and I parsed it");
}
return incomeArray;
}
【问题讨论】:
-
我将数组添加到本地存储中,但没有添加实际值。现在好了
-
哦,现在可以了吗?在 JSFiddle 上使用
localStorage有点困难,因为它有时使用域jsfiddle.net有时使用fiddle.jshell.net...
标签: javascript jquery html jquery-mobile local-storage