HTML5 localStorage adding to value with script
I'm trying to use localStorage to register the right answers to an offline game. I've got the key and value stored, and can alter it using the code below. I'd like each right answer to add to the localStorage
开发者_如何转开发 (localStorage.right plus 1), then move to the new page. Any ideas? Thank you in advance.
<input name="rightbtn" type="button" id="rightbtn" onclick="localStorage.right = '7'" value="Right" />
Should work
localStorage.right = localStorage.right++;
Or a bit nicer:
// 'right' is a bit conflict prone.
localStorage.correctAwnsers = localStorage.correctAwnsers + 1;
Note: localStorage is only supported in the latest browsers.
Note: When testing from file:// protocol, localStorage goes wonky in some browsers.
精彩评论