简体   繁体   English

HTML5 localStorage通过脚本增加价值

[英]HTML5 localStorage adding to value with script

I'm trying to use localStorage to register the right answers to an offline game. 我正在尝试使用localStorage为离线游戏注册正确的答案。 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. 我想将每个正确的答案添加到localStorage (localStorage.right加1),然后移至新页面。 Any ideas? 有任何想法吗? Thank you in advance. 先感谢您。
Code for HTML: 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. 注意:仅最新的浏览器支持localStorage。
Note: When testing from file:// protocol, localStorage goes wonky in some browsers. 注意:从file://协议进行测试时,在某些浏览器中,localStorage会变得不稳定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM