Blogger Information
Blog 18
fans 0
comment 0
visits 8456
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
简单的留言板功能
时间在渗透
Original
567 people have browsed it
  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>简单的留言板功能</title>
  8. <style type="text/css">
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. box-sizing: border-box;
  13. }
  14. body {
  15. background-image: linear-gradient(120deg, #84fab0 0%, #8fd3f4 100%);
  16. height: 98.5vh;
  17. }
  18. .container {
  19. margin: 0 auto;
  20. padding: 0 20px;
  21. max-width: 1170px;
  22. }
  23. h1 {
  24. margin: 15px 0;
  25. }
  26. textarea {
  27. display: block;
  28. width: 100%;
  29. height: auto;
  30. min-height: 300px;
  31. line-height: 20px;
  32. margin-bottom: 20px;
  33. padding: 5px 10px;
  34. border: 1px solid transparent;
  35. border-radius: 2px;
  36. transition: all .3s;
  37. outline: 0;
  38. resize: vertical;
  39. }
  40. textarea:focus {
  41. border-color: #03a9f4 !important;
  42. }
  43. button {
  44. min-width: 100px;
  45. height: 38px;
  46. line-height: 38px;
  47. border: 1px solid #eaeaea;
  48. color: #666;
  49. padding: 0 18px;
  50. background-color: #fff;
  51. text-align: center;
  52. font-size: 14px;
  53. border-radius: 2px;
  54. cursor: pointer;
  55. transition: all .3s;
  56. }
  57. button:hover {
  58. opacity: .8;
  59. border-color: #03a9f4;
  60. }
  61. .list>li {
  62. display: flex;
  63. place-content: space-between;
  64. background-color: #fff;
  65. line-height: 36px;
  66. margin-bottom: 5px;
  67. border-radius: 5px;
  68. padding: 0 8px;
  69. }
  70. </style>
  71. </head>
  72. <body>
  73. <div class="container">
  74. <h1 style="text-align: center;">留言板</h1>
  75. <div class="message" style="margin-bottom: 20px;">
  76. <textarea placeholder="请输入留言内容, 也可以使用快捷键Ctrl+Enter提交"></textarea>
  77. <div style="text-align: right;">
  78. <button>提交</button>
  79. </div>
  80. </div>
  81. <ul class="list">
  82. </ul>
  83. </div>
  84. <script>
  85. let text = document.querySelector("textarea");
  86. let btn = document.querySelector("button");
  87. let list = document.querySelector(".list");
  88. // 监听提交快捷键: Ctrl+Enter
  89. text.addEventListener('keypress', function (event) {
  90. if (event.key == "\n") {
  91. btn.click();
  92. }
  93. })
  94. // 监听点击提交按钮
  95. btn.addEventListener('click', function (event) {
  96. submit();
  97. })
  98. function submit() {
  99. if (text.value.length === 0) {
  100. alert('留言不能为空');
  101. text.focus();
  102. return false;
  103. }
  104. let itemsView = `
  105. <li>
  106. <div>${text.value}</div>
  107. <div>${getDate()}</div>
  108. </li>
  109. `;
  110. list.insertAdjacentHTML("afterbegin", itemsView);
  111. text.value = '';
  112. alert('提交成功');
  113. }
  114. function getDate() {
  115. let date = new Date();
  116. return date.getFullYear() + '-' + date.getMonth() + '-' + date.getDay() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
  117. }
  118. </script>
  119. </body>
  120. </html>

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!