Html5 localStorage本地存储

Html5 localStorage本地存储

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  <title>Storage测试</title>  
</head>  
<body>
  <h2>Storage测试</h2>  
  <input type="text" id="save"/>
  <div id="show"></div>
  <input type="button" value="保存数据" onclick="saveStorage('save');"/> 
  <input type="button" value="读取数据" onclick="loadStorage('show');"/>
  <script type="text/javascript">
    var saveStorage = function(id)
    {
      var target = document.getElementById(id);
      // 保存数据
      localStorage["message"] = target.value;
    }
    var loadStorage = function(id)
    {
      var target = document.getElementById(id);
      // 读取数据
      target.innerHTML = localStorage["message"];
    }
  </script>
</body>
</html>

 

发表回复

您的电子邮箱地址不会被公开。