-2
LocalStorageの既存の金額に数値を加算します。私は後に見つけること...確かに新しい量があることが認識されているが、私はページを更新するとき、それはのlocalStorageに保持しないことをLocalStorageに追加していない番号
//Just making an index
localStorage.setItem("currentUser",10)
//This makes currentUser.whatever into something viable
var currentUser = (JSON.parse(localStorage.getItem('usersArray')))[localStorage.getItem("currentUser")];
//I add the number to the pre-existing amount
currentUser.goldAmount = currentUser.goldAmount + 50;
//For reference 100 is a pre-existing amount for goldAmount, so it should now be 120. It does alert that although when i refresh the page and do it again its not 200, but still 150. It resets back to 100 every restart...
alert(currentUser.goldAmount);
助けに感謝です。 )
ようにそれを読む必要がない数という 注意? – JJJ
再度値を変更した後は、localstorageに設定するか、更新しないでください。 – Manish
更新された値をlocalStorageに保存する必要があります。また、すべてがローカルストアの "文字列"として保存されることに注意してください。正しい数学演算のために値を解析する必要があります。 –