html的留言板制作(js)
这次留言板运用到了最基础的localstorage的本地存储,展现的效果主要有:
1.编写留言
2.留言前可以编辑自己的留言昵称。
不足之处:
1.未能做出我喜欢的类似于网易的叠楼功能。
2.未能显示评论楼层(可实现,但是插进去十分不美观)。
编辑效果如下:

文件为html文件,编写的方式主要为div+css布局和js。本人的有点在于编写类似于后台功能和js的实现较快。但是缺点在于前端的编写较为薄弱。
在学长的帮助下前端的设计还是比较美观的。下面我将开放记事本的全部源码。
<!DOCTYPE HTML>
<html>
<head>
<meta charset="gb2312">
<title>记事本</title>
<style type="text/css">
*{margin:; padding:;}
body,input{font-size:14px; line-height:24px; color:#; font-family:Microsoft yahei, Song, Arial, Helvetica, Tahoma, Geneva;}
h1{margin-bottom:15px; height:100px; line-height:100px; text-align:center; font-size:24px; color:#fff; background:black;}
#content #post,#comment p{zoom:;}
#content #post:after,#comment p:after{display:block; height:; clear:both; visibility:hidden; overflow:hidden; content:'.';}
.transition{-webkit-transition:all .5s linear; -moz-transition:all .5s linear; -o-transition:all .5s linear; -ms-transition:all .5s linear; transition:all .5s linear;}
#content{margin: auto; width:960px; overflow:hidden;}
#content #post{margin-bottom:15px; padding-bottom:15px; border-bottom:1px #d4d4d4 dashed;
height: 556px;
}
#content #post textarea{display:block; margin-bottom:10px; padding:5px; width:948px; height:390px; border:1px #d1d1d1 solid; border-radius:5px; resize:none; outline:none;}
#content #post textarea:hover{border:1px #9bdf70 solid; background:#f0fbeb;}
#content #post #postBt,#content #post #clearBt{margin-left:5px; padding:3px; float:right;}
#comment{overflow:hidden;}
#comment p{margin-bottom:10px; padding:10px; border-radius:5px;}
#comment p:nth-child(odd){border:1px solid #e3e197; background:#ffd;}
#comment p:nth-child(even){border:1px solid #adcd3c; background:#f2fddb;}
/*#comment p span{display:inline; float:left;}*/
#comment p .right{text-align:right;}
#comment p .msg{width:738px;}
#comment p .datetime{width:200px; color:#; text-align:right;} </style>
<script type="text/javascript">
var named;
function delete1(id)
{
localStorage.removeItem(id);
this.Storage.writeData();
}
function prom() { var name = prompt("请输入您的名字", "");//将输入的内容赋给变量 name ,
named = name;
//这里需要注意的是,prompt有两个参数,前面是提示的话,后面是当对话框出来后,在对话框里的默认值 if (named)//如果返回的有内容 { alert("欢迎您:" + name)
document.getElementById("shangtian").style.display = "none";
document.getElementById("ritian").value = named; }
else {
document.getElementById("ritian").value = "匿名发言者";
} }
var Storage =
{
saveData:function()//保存数据
{ var data = document.querySelector("#post textarea");
if(data.value != "")
{
var time = new Date().getTime() + Math.random() * ;//getTime是Date对象中的方法,作用是返回 1970年01月01日至今的毫秒数
if (named) {
localStorage.setItem(time, data.value + "|" + named + "|" + this.getDateTime());//将毫秒数存入Key值中,可以降低Key值重复率
}
else
{
localStorage.setItem(time, data.value + "|" + "匿名发言者" + "|" + this.getDateTime());//将毫秒数存入Key值中,可以降低Key值重复率
} data.value = "";
this.writeData();
}
else
{
alert("请填写您的留言!");
}
},
writeData:function()//输出数据
{
var dataHtml = "", data = "";
for(var i = localStorage.length-; i >= ; i--)//效率更高的循环方法
{
data = localStorage.getItem(localStorage.key(i)).split("|"); //dataHtml += "<p><span class=\"msg\">" + data[0] + "</span><span class=\"datetime\">" + data[1] + "</span><span>" + data[2]+"</span></p>";
dataHtml += "<span style=>" + data[] + "<span style=\"float:right\">" + data[] + "</span><p><span class=\"msg\">" + data[] + "<input style=\"float:right;border:none;border-radius:5px;\" id=\"clearBt\" type=\"button\" onclick=\"delete1(" + localStorage.key(i) + ");\" value=\"删除\"/>" + "</span></p>";
}
document.getElementById("comment").innerHTML = dataHtml;
},
clearData:function()//清空数据
{
if(localStorage.length > )
{
if(window.confirm("清空后不可恢复,是否确认清空?"))
{
localStorage.clear();
this.writeData();
}
}
else
{
alert("没有需要清空的数据!");
}
},
getDateTime:function()//获取日期时间,例如 2012-03-08 12:58:58
{
var isZero = function(num)//私有方法,自动补零
{
if(num < )
{
num = "" + num;
}
return num;
} var d = new Date();
return d.getFullYear() + "-" + isZero(d.getMonth() + ) + "-" + isZero(d.getDate()) + " " + isZero(d.getHours()) + ":" + isZero(d.getMinutes()) + ":" + isZero(d.getSeconds());
}
} window.onload = function()
{
Storage.writeData();//当打开页面的时候,先将localStorage中的数据输出一边,如果没有数据,则输出空
document.getElementById("postBt").onclick = function(){Storage.saveData();}//发表评论按钮添加点击事件,作用是将localStorage中的数据输出
document.getElementById("clearBt").onclick = function(){Storage.clearData();}//清空所有已保存的数据
} </script>
</head> <body>
<h1>留言板</h1> <div id="content">
<div id="post">
<div style="background:#3EADC5 ;height:30px;">
昵称:<input type="submit" id="shangtian" name="Submit3" style="border:none; background-color:#3EADC5; color:white;" value="默认用户点击改变" onclick="prom()" />
<input type="text" id="ritian" style="border:none; background-color:#3EADC5; color:white;" onclick="prom()"/>
<!--disabled="disabled"-->
</div>
<div>
<textarea class="transition"></textarea>
</div>
<input id="postBt" type="button" style="border:none; background-color:#3EADC5; color:white;border-radius:5px; width:80px; height:30px;" value="发表留言"/>
<input id="clearBt" type="button" style="border:none; background-color:#3EADC5; color:white;border-radius:5px; width:80px; height:30px;" value="清空"/>
</div>
<div id="comment"></div>
</div>
</body>
</html>
html的留言板制作(js)的更多相关文章
- javascript-DOM操作-留言板制作
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- PHP留言板制作(MySQL+PHP)
参考视频:https://www.bilibili.com/video/BV1Js411i74j?p=8 环境:phpstudy 2018 PHP 5.X PHPmyadmin ...
- php写留言板
简单的PHP留言板制作 做基础的留言板功能 需要三张表: 员工表,留言表,好友表 首先造一个登入页面: <form action="drcl.php" method=&qu ...
- 利用Asp.net和Sql Server实现留言板功能
本教程设及到:使用SQL Server查询分析器创建数据库:SQL查询语句常用的一些属性值:触发器创建和使用:存储过程的创建,ASP使用存储过程. 正文: 一.创建数据库: 创建一个feedback数 ...
- js制作留言板
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 问题:关于一个贴友的js留言板的实现
需求:用js做一个简单的留言板效果 html部分: 1: <!DOCTYPE> 2: <html lang="zh-en"> 3: <head> ...
- [js高手之路] vue系列教程 - 实现留言板todolist(3)
通过前面两篇文章的的学习,我们掌握了vue的基本用法. 本文,就利用这些基础知识来实现一个留言板, 老外把他称之为todolist. 第一步.使用bootstrap做好布局 <!DOCTYPE ...
- 用js做一个简单的留言板效果
html部分: 1: <!DOCTYPE> 2: <html lang="zh-en"> 3: <head> 4: <title>j ...
- 留言板(初学者使用js实现)
代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
随机推荐
- Azure Redis Cache
将于 2014 年 9 月 1 日停止Azure Shared Cache服务,因此你需要在该日期前迁移到 Azure Redis Cache.Azure Redis Cache包含以下两个层级的产品 ...
- 【腾讯Bugly干货分享】让 CodeReview 这股清流再飞一会儿
本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:https://mp.weixin.qq.com/s/ToYeT4Y4pzx0ii9Z92fo-Q 作者:刘 ...
- 收集最好的Mac软件和使用方法
MacBook 初体验 作者是刚从Windows下转到mac时写的,这篇文章对也主要介绍了Mac下开发环境的部署.软件的安装和卸载.常用快捷键.文件系统的介绍. http://liujiacai.ne ...
- Hibernate 延迟加载原理
如何简单的理解延迟加载?开发中常见的org.hibernate.LazyInitializationException no session错误又是怎么产生的?下面通过一个简单的例子来解析一下 ...
- Swift 和 C# 的语法比较
昨天看到Jacob Leverich 写了一篇文章 Swift is a lot like Scala 介绍Swift 和 Scala 的语法对比,从这篇文章的确可以看到Swift 的语法和 Scal ...
- ASP.Net中通过Jquery前端对Repeater控件绑定的数据进行操作
说明:由于Repeater控件是动态绑定,通过Id获取数据只能默认获取第一行: 1.对Repeater中div设置样式 2.通过$(".css").each(function(){ ...
- iOS----支付(微信支付、支付宝支付、银联支付控件集成支付)(转)
资料 支付宝 //文档idk都包含了安卓.iOS版 银 联 银联官网资料 Demo Demo给了一个订单号,做测试使用,若出现支付失败什么的,可能是已经被别人给支付了,或者是服务器订单过期了 ~ 一. ...
- SSIS Design1: 源数据提取
数据量的大小由两个方面决定:行的宽度和数据行的数量,为了减少ETL运行的时间,可以从源数据的提取上做优化,从数据源的输入上控制数据的质量和大小,减少转换和IO. 一,减少行的宽度 1,只加载需要的数据 ...
- Utility1:Overview
Utility 是利用,使用的意思,utilization是指使用效率,利用率的意思. SQL Sever 内置 Utility Feature,便于集中监控Server关键资源(CPU和Disk)的 ...
- Spark中决策树源码分析
1.Example 使用Spark MLlib中决策树分类器API,训练出一个决策树模型,使用Python开发. """ Decision Tree Classifica ...