DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> JS localStorage實現本地緩存的方法
JS localStorage實現本地緩存的方法
編輯:關於JavaScript     

復制代碼 代碼如下:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>本地緩存</title>
    <script type="text/javascript">
        var strKey = "strKey";
        var storage = window.localStorage;

        function onStart(){
            if(storage.getItem(strKey)!=null){
                alert(storage.getItem(strKey)+'localStorage');
            }else if(Cookie.read(strKey)!=null){
                alert(Cookie.read(strKey)+'cookie');
            }
        }
        function bendihuancun(){
            var strValue = document.getElementById("username").value;
            if (storage) {
            storage.setItem(strKey, strValue);  
        } else {
            Cookie.write(strKey, strValue); 
        }
        }
    </script>
  </head>
  <body onload="onStart()">
    <input type="text" id="username" value="123">
    <input type="button" value="保存緩存" onclick="bendihuancun()">
  </body>
</html>

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved