博客列表 >修改留言板

修改留言板

手机用户1580651468
手机用户1580651468原创
2022年11月13日 14:56:54852浏览

修改留言板

一. 改写留言板案例,适当添加CSS美化

一)html代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=], initial-scale=1.0" />
  7. <title>todoList:留言板</title>
  8. <link rel="stylesheet" href="css/font-icon.css" />
  9. </head>
  10. <body>
  11. <style>
  12. .list {
  13. list-style: none;
  14. }
  15. .title a {
  16. text-decoration: none;
  17. }
  18. .title1 a {
  19. margin: 0;
  20. text-decoration: none;
  21. }
  22. .title1 h {
  23. list-style: none;
  24. }
  25. .title1 {
  26. height: 50px;
  27. width: 699px;
  28. border: 1px solid red;
  29. text-align: center;
  30. background-color: brown;
  31. display: table;
  32. }
  33. .title1 > a {
  34. font-size: x-large;
  35. background-color: lawngreen;
  36. display: table-cell;
  37. vertical-align: middle;
  38. background-image: url(image/title1.png);
  39. background-size: auto 100%;
  40. }
  41. .title1 > .Subtitle {
  42. background-color: blue;
  43. margin: 0;
  44. }
  45. .title {
  46. height: 50px;
  47. width: 684px;
  48. border-top: 1px solid red;
  49. border-left: 1px solid red;
  50. border-right: 1px solid red;
  51. text-align: center;
  52. }
  53. .title.navigation {
  54. display: flex;
  55. place-items: center;
  56. padding-left: 15px;
  57. gap: 20px;
  58. }
  59. .title.navigation a {
  60. font-size: large;
  61. }
  62. .content {
  63. width: 700px;
  64. display: grid;
  65. grid-template-columns: 500px 1fr;
  66. grid-template-rows: 200px 100px;
  67. margin: 1px;
  68. gap: 5px;
  69. }
  70. .members {
  71. grid-row: span 2;
  72. border: 1px solid red;
  73. display: grid;
  74. grid-template-rows: 100px 200px;
  75. gap: 2px;
  76. }
  77. .members .group {
  78. border: 1px solid red;
  79. background-color: yellowgreen;
  80. }
  81. .DisplayBox {
  82. height: 200px;
  83. width: 500px;
  84. border-top: 1px solid red;
  85. border-left: 1px solid red;
  86. border-right: 1px solid red;
  87. }
  88. .Input > .nav > .expression {
  89. text-decoration: none;
  90. }
  91. .nav {
  92. height: 20px;
  93. border: none;
  94. display: flex;
  95. gap: 15px;
  96. }
  97. .nav > a {
  98. color: darkgrey;
  99. }
  100. .Button {
  101. height: 40px;
  102. text-align: right;
  103. font-size: x-large;
  104. }
  105. input {
  106. height: 40px;
  107. border: none;
  108. }
  109. .Input.area {
  110. height: 100px;
  111. width: 500px;
  112. border: 1px solid red;
  113. }
  114. </style>
  115. <div class="title1">
  116. <a href=""></a>
  117. </div>
  118. <div class="title navigation">
  119. <a href="">聊天</a>
  120. <a href="">公告</a>
  121. <a href="">相册</a>
  122. <a href="">文件</a>
  123. <a href="">作业</a>
  124. <a href="">设置</a>
  125. </div>
  126. <div class="content">
  127. <div>
  128. <div class="DisplayBox">
  129. <ul class="list">
  130. <li><button>删除</button></li>
  131. <li><button>删除</button></li>
  132. </ul>
  133. </div>
  134. <div class="Input area">
  135. <div class="nav">
  136. <a href="" class="iconfont unicode">&#xe60e;</a>
  137. <a href="" class="iconfont unicode">&#xe70d;</a>
  138. <a href="" class="iconfont unicode">&#xe6e8;</a>
  139. <a href="" class="iconfont unicode">&#xe64c;</a>
  140. <a href="" class="iconfont unicode">&#xe6ff;</a>
  141. <a href="" class="iconfont unicode">&#xe6eb;</a>
  142. </div>
  143. <input
  144. type="text"
  145. onkeydown="insertComment(this)"
  146. placeholder="请输入留言"
  147. />
  148. <div class="Button">
  149. <button>关闭</button>
  150. <button>发送</button>
  151. </div>
  152. </div>
  153. </div>
  154. <div class="members">
  155. <div class="group Notice">
  156. <a href="">群通知</a>
  157. </div>
  158. <div class="group members1">
  159. <a href="">群成员</a>
  160. </div>
  161. </div>
  162. </div>
  163. <script>
  164. const insertComment = function (ele) {
  165. // 1.非空判断
  166. // console.log(ele)
  167. // console.log(event);
  168. // console.log(event.type);
  169. // console.log(event.key);
  170. if (event.key === "Enter") {
  171. if (ele.value.length === 0) {
  172. alert("留言不能为空");
  173. ele.focus();
  174. return false;
  175. }
  176. // 2.添加留言
  177. // console.log(ele.value);
  178. // 创造一个新元素来保存留言
  179. // const li = document.createElement("li");
  180. // li.append(ele.value);
  181. // const ul = document.querySelector(".list");
  182. // if (ul.firstElementChild !== null) {
  183. // ul.firstElementChild.before(li);
  184. // } else {
  185. // ul.append(li);
  186. // }
  187. const ul = document.querySelector(".list");
  188. ele.value += `<button onclick="del(this.parentNode)" >删除</button>`;
  189. ul.insertAdjacentHTML(`beforeend`, `<li>${ele.value}</li>`);
  190. // 3.清空输入框
  191. ele.value = null;
  192. }
  193. };
  194. // 删除
  195. const del = function () {
  196. confirm("是否删除?") ? ele.remove() : false;
  197. };
  198. </script>
  199. </body>
  200. </html>

二)实现效果图

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议