码迷,mamicode.com
首页 > Web开发 > 详细

简单Web留言本

时间:2015-08-30 20:54:33      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:

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>


简单Web留言本

标签:

原文地址:http://www.cnblogs.com/htmlphp/p/4771433.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!