留言板功能css美化

图片

留言

代码

  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=device-width, initial-scale=1.0" />
  7. <title>留言板</title>
  8. <style>
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. box-sizing: border-box;
  13. }
  14. li {
  15. list-style: none;
  16. }
  17. a {
  18. text-decoration: none;
  19. }
  20. body {
  21. margin: auto;
  22. }
  23. .box {
  24. width: 100vw;
  25. display: grid;
  26. grid-template-rows: 60px 100px 1fr;
  27. }
  28. .box .title {
  29. height: 50px;
  30. border-bottom: 1px solid #333;
  31. }
  32. .box .content input:hover {
  33. box-shadow: 2px 2px 10px #06c;
  34. }
  35. .box .content {
  36. display: grid;
  37. grid-template-rows: 1fr 33px;
  38. }
  39. .box .content button {
  40. width: 70px;
  41. height: 32px;
  42. line-height: 32px;
  43. background-color: #009688;
  44. color: #fff;
  45. white-space: nowrap;
  46. text-align: center;
  47. font-size: 14px;
  48. border: none;
  49. border-radius: 2px;
  50. margin-top: 10px;
  51. place-self: start end;
  52. }
  53. .box .list {
  54. margin-top: 20px;
  55. }
  56. .box .list li {
  57. display: grid;
  58. grid-template-columns: 1fr 50px;
  59. place-content: space-between;
  60. }
  61. .box .list li {
  62. padding: 3px 0;
  63. background-color: #f4f4f4;
  64. border-bottom: 1px solid #333;
  65. }
  66. .box .list li button {
  67. background-color: orangered;
  68. color: #fff;
  69. white-space: nowrap;
  70. text-align: center;
  71. font-size: 14px;
  72. border: none;
  73. border-radius: 2px;
  74. }
  75. .box .list li button:hover {
  76. box-shadow: 0px 0px 10px red;
  77. }
  78. </style>
  79. </head>
  80. <body>
  81. <hr />
  82. <div class="box">
  83. <h1 class="title">留言板</h1>
  84. <div class="content">
  85. <textarea
  86. name=""
  87. class="ele"
  88. cols="30"
  89. rows="4"
  90. placeholder="内容不能为空"
  91. autofocus
  92. ></textarea>
  93. <button onclick="addMsg()">立即提交</button>
  94. </div>
  95. <ul class="list"></ul>
  96. </div>
  97. <script>
  98. function addMsg() {
  99. let ele = document.querySelector(".ele");
  100. if (ele.value.trim().length === 0) {
  101. alert("留言不能为空");
  102. ele.focus();
  103. return false;
  104. }
  105. const ul = document.querySelector(".list");
  106. const li = document.createElement("li");
  107. li_length = ul.children.length + 1;
  108. li.innerHTML =
  109. li_length +
  110. "楼: " +
  111. ele.value +
  112. '<button onclick="del(this.parentNode);">删除</button>';
  113. // console.log(li_length);
  114. ul.insertAdjacentElement("afterBegin", li);
  115. ele.value = null;
  116. ele.focus();
  117. }
  118. function del(ele) {
  119. if (confirm("是否删除")) {
  120. ele.remove();
  121. } else {
  122. return false;
  123. }
  124. }
  125. </script>
  126. </body>
  127. </html>

更多相关文章

  1. 留言板功能
  2. 留言板与自动客服
  3. javascript-基础(四)实战
  4. Dom实战:留言板
  5. 留言板及自动客服回复功能的实例演示
  6. 留言板实践代码
  7. JS留言板实践
  8. php PHP实现基本留言板功能原理与步骤详解
  9. 一个简单的留言板

随机推荐

  1. 将ffmpeg编译到android 源码
  2. Android中Context到底是什么以及用法
  3. 各Android版本WifiStateMachine状态机
  4. android 防止键盘弹出的简单方法
  5. Monkey
  6. Android 屏幕常亮
  7. android indication
  8. Android中实现Gallery 点击放大
  9. Android UI开发第十七篇――Android Frag
  10. Android 深入研究LBS(基于位置的服务)