H5 Web存储

2017-11-08  本文已影响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>
上一篇 下一篇

猜你喜欢

热点阅读