基于Web Storage的客户端留言板
来源:互联网 发布:金石期货软件下载 编辑:程序博客网 时间:2024/06/06 05:21
一 代码
<!DOCTYPE html><html><head><meta name="author" content="Yeeku.H.Lee(CrazyIt.org)" /><meta http-equiv="Content-Type" content="text/html; charset=GBK" /><title> 客户端留言板 </title><style type="text/css">table {border-collapse: collapse;}td , th{border: 1px solid #888;padding: 4px;}</style></head><body><h2>客户端留言板</h2><textarea id="msg" name="msg" cols="50" rows="8"></textarea><br/><input type="button" value="添加留言" onclick="addMsg();"/><input type="button" value="清除留言" onclick="clearMsg();"/><hr/><table style="width:550px"><tr><th>留言内容</th><th>留言时间</th></tr><tbody id="show"></tbody></table><script type="text/javascript">// 加载留言信息var loadMsg = function(){var tb = document.getElementById("show");// 清空原来显示的内容。tb.innerHTML = "";// 遍历所有留言信息for(var i = 0 ; i < localStorage.length ; i++){var key = localStorage.key(i);var date = new Date();date.setTime(key);// 获取留言时间var datestr = date.toLocaleDateString()+ " " + date.toLocaleTimeString();// 获取留言内容var value = localStorage.getItem(key);var row = tb.insertRow(i);// 添加第一个单元格,并显示留言内容row.insertCell(0).innerHTML = value;// 添加第二个单元格,并显示留言内容。row.insertCell(1).innerHTML = datestr;}}var addMsg = function(){var msgElement = document.getElementById("msg");var time = new Date().getTime();// 以当前时间为key来保存留言信息localStorage.setItem(time , msgElement.value);msgElement.value = "";alert("数据已保存。");loadMsg();}function clearMsg(){// 清空Local Storage里保存的数据。localStorage.clear();alert("全部留言信息已被清除。");loadMsg();}window.onload = loadMsg();</script></body></html>
二 运行效果
阅读全文
0 0
- 基于web storage的客户端留言板
- 基于Web Storage的客户端留言板
- web Storage 客户端存储
- Web Storage结构化存储实现更复杂的本地留言板
- 基于mvc的留言板
- Web Storage:简单强大的客户端数据存储技术
- 开发基于XML的留言板
- 开发基于XML的留言板
- 开发基于XML的留言板
- 基于XML的ASP留言板
- 基于MVC的简易留言板
- HTML-Storage留言板
- HTML5的Web Storage
- HTML的Web Storage
- 基于Web页面的桌面客户端框架
- 基于SOAP的Web服务AJAX客户端
- 基于REST的Web服务器客户端
- web storage下的session storage和local storage
- 彻底解决Ubuntu下qt creator无法显示中文问题
- ionic2中实现 IndexedDB
- 使用intellij idea 创建tomcat项目的时候会出现该错误:
- Android的设计模式-责任链模式
- (转)Android App 启动页(Splash)黑/白闪屏现象产生原因与解决办法
- 基于Web Storage的客户端留言板
- 消失点检测资料
- VS2013下编译opencv3.1.0及其对应contrib库
- WebStorm WiFi真机同步无法安装成功及appLoader无法连接
- 用Axure撰写产品需求文档
- Web Storage结构化存储实现更复杂的本地留言板
- 构建web离线应用
- 机器学习(一)-----K近邻算法
- 判断浏览器在线状态