Blogger Information
Blog 21
fans 0
comment 0
visits 10041
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
留言板案例,添加CSS美化
放手去爱
Original
475 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>todoList: 留言板</title>
  8. </head>
  9. <style>
  10. * {
  11. margin: 0;
  12. padding: 0;
  13. box-sizing: border-box;
  14. }
  15. html {
  16. font: size 100px;
  17. }
  18. input {
  19. margin: 5px 0px 5px 25px;
  20. padding: 5px;
  21. width: 299px;
  22. height: 30px;
  23. }
  24. input:focus {
  25. background: #67e49f;
  26. }
  27. ul.list {
  28. width: 310px;
  29. border: 0.01px solid salmon;
  30. border-radius: 5px;
  31. margin-left: 20px;
  32. }
  33. ul.list > li {
  34. margin: 2px 5px;
  35. padding: 5px;
  36. width: 300px;
  37. height: 30px;
  38. background: #525252;
  39. color: #fcf8f8;
  40. border-radius: 5px;
  41. vertical-align: middle;
  42. }
  43. ul.list > li:hover {
  44. width: 300px;
  45. height: 30px;
  46. background: #cf6b6b;
  47. color: #fcf8f8;
  48. border-radius: 5px;
  49. vertical-align: middle;
  50. }
  51. ul.list > li button {
  52. float: right;
  53. width: 60px;
  54. background: #525252;
  55. border-radius: 5px;
  56. color: #fcf8f8;
  57. }
  58. ul.list > li button:hover {
  59. float: right;
  60. width: 60px;
  61. background: #67e49f;
  62. border-radius: 5px;
  63. color: #fcf8f8;
  64. }
  65. </style>
  66. <body>
  67. <input
  68. type="text"
  69. onkeydown="insertComment(this)"
  70. placeholder="请输入留言"
  71. autofocus
  72. />
  73. <ul class="list">
  74. <!-- 其实每一条新留言,应该添加到ul的起始标签的后面: afterbegin -->
  75. </ul>
  76. <script>
  77. const insertComment = function (ele) {
  78. // 只有按下回车键才提交
  79. if (event.key === "Enter") {
  80. // 1. 非空判断
  81. if (ele.value.length === 0) {
  82. // 提示用户
  83. alert("留言不能为空");
  84. // 重置焦点
  85. ele.focus();
  86. // 直接返回
  87. return false;
  88. }
  89. // 2. 添加留言
  90. const ul = document.querySelector(".list");
  91. ele.value += `<button onclick="del(this.parentNode)">删除</button>`;
  92. ul.insertAdjacentHTML("afterbegin", `<li>${ele.value}</li>`);
  93. // 3. 清空输入框
  94. ele.value = null;
  95. }
  96. };
  97. // 删除
  98. const del = function (ele) {
  99. return confirm("是否删除?") ? (ele.outerHTML = null) : false;
  100. };
  101. </script>
  102. </body>
  103. </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