美文网首页
H5 Web存储

H5 Web存储

作者: 不语翕 | 来源:发表于2017-11-08 18:09 被阅读0次
  <!DOCTYPE>
  <html>
    <head>
        <meta charset="UTF-8">
        <title>Web存储</title>
    </head>
    <body>
         <h2>sessionStorage</h2>
        <script type="text/javascript">
            if(sessionStorage.hits){
                sessionStorage.hits = Number(sessionStorage.hits)+1;
            }else{
                sessionStorage.hits = 1;
            }
            document.write("Total SessionStorage Hits :"+ sessionStorage.hits);
        </script>
        <h2>localStorage</h2>
        <script type="text/javascript">
           localStorage.clear();  //清除所有本地存储
           localStorage.remove('key'); //清除指定key的存储
           if( localStorage.hits ){
            localStorage.hits = Number(localStorage.hits)+1;
           }else{
            localStorage.hits = 1;
           }
           document.write("Total LocalStorage Hits:"+localStorage.hits );
        </script>
        <p>Refresh the page to increase number or hits.</p>
        <p>Close the windows and open it again and check the result.</p>
    </body>
  </html>

相关文章

网友评论

      本文标题:H5 Web存储

      本文链接:https://www.haomeiwen.com/subject/rlvymxtx.html