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