开发者

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.

Code for HTML:

<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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜