如何让localStorage在todolist应用程序上工作
How to get localStorage to work on a todolist-app
我不知道localStorage是如何工作的,我的项目需要它。我正在做一个todolist应用程序,我需要保存项目,这样用户就可以关闭该应用程序,并且当他们再次打开该应用程序时,列表仍然存在。我该怎么做?
<!DOCTYPE html>
<html manifest = offline.appcache>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<link rel="shortcut icon" href="favicon.ico">
<link href="main.css" type="text/css" rel="stylesheet">
<title>Inköpslista</title>
</head>
<body>
<div id="kol1" class="kol">
<h1>Inköp</h1>
<input type="image" src="img/button.png" alt="Submit" id="storknapp" onclick="klickaKnapp('skriva')"/>
<div id="form">
<input type"text" id="skriva" placeholder="Skriv din vara här!"/>
<input type="image" id="knapp" src="img/pluss.png" alt="Submit"/>
</div>
</div>
<div id="kol2">
<ul id="listaavvara"></ul>
</div>
</body>
<script src="menudropdown.js" type="text/javascript"></script>
<script type="text/javascript" src="java.js"></script>
</html>
Cookies会降低web应用程序的速度,因此如果要将数据存储到客户端浏览器中,则可能需要使用localStorage或sessionStorage。所以如果你想要:
- 大量存储空间
- 在客户端上
- 持续到页面刷新之后
- 并且不会传输到服务器
创造价值:
localStorage.setItem("bar", foo);
获取值:
var foo = localStorage["bar"];
删除值:
localStorage.clear();
例如,如果你想创建一个列表,你可以将JSON值存储到localStorage中,比如:
localStorage.setItem("list", "[{"name":"Adriano"},{"name":"Vic"},{"name":"Test"}]");
然后,您检索它并使用JS在您的页面中进行组装。
此链接非常完美:http://diveintohtml5.info/storage.html
顺便说一句:它不像cookie那样有有效期=)
相关文章:
- Canvas Html5绘图应用程序,移动画布会导致重大问题
- Emberjs应用程序加载在除Index之外的所有路由上
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- 在AngularJS应用程序中使用封装指令和路由的推荐方式是什么
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- angular 1.5应用程序中的导航栏
- 在Web应用程序中使用Highcharts javascript
- angularjs+rails应用程序中未显示模板
- 使用acess代币登录Facebook,并通过网络应用程序离线发布
- 从HTTPGET返回一个自定义对象列表,以便在Angular 2应用程序中使用
- 科尔多瓦页面类应用程序中的多个谷歌地图
- 使用谷歌应用程序脚本将服务器端数据表返回到客户端
- Angularjs-utils高亮过滤器在搜索时破坏应用程序
- 在phonegap应用程序内部重定向不起作用
- 使用谷歌应用程序脚本从工作表中获取值并将其显示在文本框中
- MockJax没有在JavaScript应用程序中发送对我AJAX请求的响应
- Node.js正在更改应用程序以使用集群模块
- 如何加载/构建 Chrome 应用/扩展程序并以编程方式运行
- Chrome 应用/扩展程序 - 后台请求错误,或允许应用问题加载 Google 文档 API
- 检测我使用的是 chrome 应用/扩展程序