Blogger Information
Blog 24
fans 0
comment 0
visits 10897
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
留言板案例
皮皮志
Original
635 people have browsed it

html代码

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <link rel="stylesheet" href="style.css">
  9. </head>
  10. <body>
  11. <header>
  12. <div class="nav">
  13. <div>留言板</div>
  14. <div>浏览:139</div>
  15. </div>
  16. </header>
  17. <main>
  18. <div class="box">
  19. <textarea name="message" class='message' placeholder="说些什么吧" onkeydown="print(this)"></textarea>
  20. <div class="second">
  21. <textarea name="name" class='name' placeholder="昵称" onkeydown="Name(this)"></textarea>
  22. <textarea name="email" class='email' placeholder="邮箱"></textarea>
  23. <textarea name="url" class='url' placeholder="网址"></textarea>
  24. </div>
  25. <button onclick="print(this.previousElementSibling.previousElementSibling)">提交</button>
  26. </div>
  27. </main>
  28. <footer>
  29. </footer>
  30. <script src="js.js"></script>
  31. </body>
  32. </html>

css代码

  1. *{
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. body{
  7. margin: 0 200px;
  8. background-color: #fff;
  9. width: 1200px;
  10. }
  11. header .nav{
  12. margin: 50px 0 0 20px;
  13. display: grid;
  14. grid-template-columns: 100px 100px;
  15. gap: 10px;
  16. }
  17. header .nav div{
  18. background-color: skyblue;
  19. border-radius: 20px;
  20. width: 80px;
  21. height: 50px;
  22. text-align: center;
  23. line-height: 50px;
  24. }
  25. main .box{
  26. margin: 20px 0 0 20px;
  27. display: grid;
  28. grid-template-rows: 200px 50px 50px;
  29. gap: 10px;
  30. }
  31. main .box .message{
  32. display: block;
  33. height: 200px;
  34. width: 1180px;
  35. border-radius: 10px;
  36. background-color: skyblue;
  37. place-items: start;
  38. font-size: 18px;
  39. }
  40. main .box .second{
  41. display: grid;
  42. grid-template-columns: repeat(3,1fr);
  43. gap:0 10px;
  44. height: 30px;
  45. }
  46. main .box .second *{
  47. background-color: skyblue;
  48. border-radius: 10px;
  49. line-height: inherit;
  50. font-size: 22px;
  51. }
  52. footer{
  53. margin: 20px 0 0 20px;
  54. background-color: skyblue;
  55. border-radius: 10px;
  56. }
  57. footer .answer{
  58. color:red
  59. }

js代码

  1. const print = function (ele){
  2. let arr = ["老板发财","老板有钱","老板你好","我是你爹","我是你爸爸","你吃了吗","你吃饱了吗"]
  3. let nameArr = ["张三",'李四','王二麻子','跳跳虎','啊狗','狗蛋','驴']
  4. if(event.key === 'Enter' || event.type ==='click'){
  5. if(ele.value.length === 0){
  6. alert('留言不可为空');
  7. ele.focus()
  8. return false
  9. }
  10. const div = document.querySelector('footer')
  11. div.insertAdjacentHTML("afterbegin",`<div class="box1">
  12. <p>当前时间:${time()}</p>
  13. <p>${nameArr[(Math.round(Math.random()*(arr.length-1)))]}说:${ele.value}</p>
  14. <p class="answer">平台回复:${arr[(Math.round(Math.random()*(arr.length-1)))]}</p>
  15. </div> `)
  16. ele.value = null
  17. }
  18. }
  19. const time = function show(){
  20. new Date();
  21. setTimeout(show,1000);//定时器一直调用show()函数
  22. return new Date();
  23. }

代码展示如下

留言

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:很好, 效果不错, 整体没什么问题
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post