标签:phonegap的stroage存储数据 phonegap开发 localstorage sessionstorage storage存储数据
<html>
<head>
<title>localStorage存储数据</title>
<script type="text/javascript">
//设置name对应的值
localStorage.setItem("name", "刘备");
//得到name对应的值
var name = localStorage.getItem("name");
//删除指定key为name的值
localStorage.removeItem("name");
//清空
localStorage.clear();
</script>
</head>
<body>
<div>
localStorage作为HTML5本地存储Web Storage特性的API之一,主要作用是将数据保存在客户端中
localStorage保存的数据,一般情况下是永久保存的。直到用户删除数据,数据的生命周期才会结束。
</div>
</body>
</html>
<html>
<head>
<title>sessionStorage存储数据</title>
<script type="text/javascript">
//设置name对应的值
sessionStorage.setItem("name", "刘备");
//得到name对应的值
var name = sessionStorage.getItem("name");
//删除指定key为name的值
sessionStorage.removeItem("name");
//清空
sessionStorage.clear();
</script>
</head>
<body>
<div>
sessionStorage作为HTML5本地存储Web Storage特性的API之一,主要作用是将数据保存在当前回话
</div>
</body>
</html>
<html>
<head>
<title>监听Storage</title>
<script type="text/javascript">
window.onload = function() {
window.addEventListener("storage", function(e) {
console.log(e);
}, true);
localStorage.clear();
localStorage.setItem("name", "刘备");
localStorage.setItem("name", "曹操");
}
</script>
<script type="text/javascript">
if (window.navigator.onLine) {
//在线
} else {
//离线
}
</script>
</head>
<body>
</body>
</html>
标签:phonegap的stroage存储数据 phonegap开发 localstorage sessionstorage storage存储数据
原文地址:http://blog.csdn.net/y_f123/article/details/42211739