PhoneGap的Stroage存储数据的方式

来源:互联网 发布:淘宝护肤品假货 编辑:程序博客网 时间:2024/06/08 11:07

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

 

0 0
原创粉丝点击