<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="appWeb.js"></script>
</head>
<body>
<p id="msg"></p>
<textarea id="memo" cols="60" rows="10"></textarea><br/>
<input type="button" value="追加数据" onclick="saveStorage('memo')">
<input type="button" value="删除数据" onclick="clearStorage()">
</body>
</html>
/**
* Created by Eagles on 2015/9/5.
*/ function saveStorage(id) {
var data = document.getElementById(id).value;
var time = new Date().getTime();
// 保存数据的方法 key value
localStorage.setItem(time, data);
alert("数据已储存");
loadStorage("msg");
loadStorage("msg");
} function loadStorage(id) {
var result = "<table border = '2'>";
for(var i=0; i<localStorage.length;i++){
var key = localStorage.key(i);
var value = localStorage.getItem(key);
var date = new Date();
date.setTime(key);
result += "<tr><td>"+value+"</td><td>"+date+"</td></tr>";
}
result += "</table>";
var target = document.getElementById(id);
target.innerHTML = result;
} function clearStorage(){
localStorage.clear();
alert("数据已经删除");
loadStorage("msg");
}