【发布时间】:2015-07-02 21:10:55
【问题描述】:
我正在尝试显示已存储在本地存储中的数组中的值。我已经能够将值存储在本地存储中,并在单击按钮时添加其他值,但我无法检索这些值并将它们显示在页面上。
这是我向本地存储添加值的代码。
$("#player1Link").click(function() {
if (localStorage.getItem("player1Favourite") !== null) {
var a = JSON.parse(localStorage.getItem('player1Favourite'));
if (a.indexOf(chosenPlayerId) === -1) {
a.push(chosenPlayerId);
localStorage.setItem('player1Favourite', JSON.stringify(a));
alert("Pushed in");
} else {
alert("Already in favourites");
}
} else {
var a = [];
a.push(chosenPlayerId);
localStorage.setItem('player1Favourite', JSON.stringify(a));
}
})
我希望能够单击一个按钮来检索值并将它们显示在页面上,但我可以找出要在此函数中执行的代码。
$("#playerRetrieve").click(function() {});
如果有人可以提供帮助,将不胜感激。
【问题讨论】:
标签: javascript jquery arrays local-storage