简易留言板的实现

简易留言板的实现

本文实现一个简易的留言板

本文的看点在于实现了留言的动态插入。

效果图如下:

<style>/* 留言框 */ form fieldset{ width:200px;}/* 留言区CSS */.container{/* border: 1px solid gray; */ maxwidth:600px;}.container .note{ border:1px solid burlywood; display: grid;}.container .note div:lastoftype{ textalign: right; fontsize: x; fontfamily:Courier 搭建源码点我wcqh.cnNew,Courier, monospace;}.container .reply{ borderbottom:2px solid red;}</style></head><body><!– 1. 改写留言板案例,适当添加CSS美化 2. (选做), 将留言板案例改成”智能客服系统”,实现机器人回复 –><h4>意见框:</h4><formaction=“#”method=“post”name=“myForms_1”><fieldset><legend>请留下您的宝贵意见:</legend><textareaname=“note”id=“note”cols=“30”rows=“10”placeh搭建源码点我wcqh.cnolder=“留言后点击提交”autofocus></textarea><br><br><buttontype=“button”onclick=tijiao()>提交</button></fieldset></form><br><br><!– 以下为留言区 –><p>留言区</p><divclass=“container”><divclass=“note”><div></div><div></div></div><divclass=“reply”></div></div> // 获取form表单 let forms = document.forms.myForms_1;// 获取留言区的DOM搭建源码点我wcqh.cn元素 let container = document.querySelector(.container); let note = document.querySelector(.note); let note_1 = note.firstElementChild; let note_2 = note.lastElementChild; let reply = document.querySelector(.reply);// 留言提交函数function tijiao(){ let trLength = note.children.length; console.log(trLength); console.log(forms.no搭建源码点我wcqh.cnte.value); let value = forms.note.value; let date =newDate(); let time = date.getFullYear()+“年”+date.getMonth()+“月”+date.getDay()+“日”+date.getHours()+“点”+date.getMinutes()+“分”;// 将内容放到模板字面量里 let noteDiv =`<div class=“note”><div>${value}</div><div>${time}</div></div><div class=”reply”>”您好,你的留言已经收到”</div>`;// 将内搭建源码点我wcqh.cn容插入留言区 container.insertAdjacentHTML(“afterbegin”,noteDiv); forms.note.value=“”;}
批改老师:PHPz 批改状态:合格 老师批语:好, 一如既往, 看的出用心了, 继续加油
作者最新博文
2022-10-15 02:50:43

© 版权声明
THE END
喜欢就支持一下吧
点赞492 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容