标签:
appWeb2.js
/**
* Created by hp on 2015/8/30.
*/
function saveStorage(id){
var data = document.getElementById(id).value;
var time = new Date().getTime();
localStorage.setItem(time,data);
alert("数据已存储");
loadStorage(‘msg‘);
}
function loadStorage(id){
var result = "<table border= ‘1‘>";
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‘);
}
Web2.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="appWeb2.js"></script>
</head>
<body>
<p id="msg"></p>
<textarea cols="60" rows="10" id="memo"></textarea>
<br />
<input type="button" value="追加数据" onclick="saveStorage(‘memo‘)">
<input type="button" value="删除数据" onclick="clearStorage(‘msg‘)">
</body>
</html>
标签:
原文地址:http://www.cnblogs.com/htmlphp/p/4771433.html