实现的一个网页版的简易表白墙

梦里梦外; 2024-05-06 21:25 135阅读 0赞

实现的一个网页版的表白墙

实现效果

image-20240307134439192

代码截图

image-20240307215605013

相关代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <div class="container">
  10. <h1>表白墙</h1>
  11. <P>输入相关信息,点击提交后将会展示在表格中</P>
  12. <div class="div1">
  13. <span>谁:</span><input type="text" class="edit">
  14. </div>
  15. <div class="div1">
  16. <span>对谁:</span><input type="text" class="edit">
  17. </div>
  18. <div class="div1">
  19. <span>说:</span><input type="text" class="edit">
  20. </div>
  21. <div class="div1">
  22. <input type="button" value="提交" class="submit" onclick="Submit()">
  23. </div>
  24. </div>
  25. </body>
  26. <style>
  27. * {
  28. margin: 0px;
  29. padding: 0px;
  30. }
  31. .container {
  32. width: 400px;
  33. margin: 0 auto;
  34. }
  35. h1 {
  36. text-align: center;
  37. margin-bottom: 20px;
  38. margin-top: 40px;
  39. }
  40. p {
  41. text-align: center;
  42. color: gray;
  43. line-height: 63px;
  44. }
  45. .div1 {
  46. display: flex;
  47. justify-content: center;
  48. align-items: center;
  49. }
  50. .edit {
  51. margin-bottom: 20px;
  52. width: 200px;
  53. height: 30px;
  54. }
  55. span {
  56. width: 50px;
  57. margin-bottom: 20px;
  58. }
  59. .submit {
  60. background-color: rgb(255, 136, 0);
  61. color: white;
  62. width: 254px;
  63. height: 40px;
  64. border: none;
  65. border-radius: 5px;
  66. }
  67. .submit:active {
  68. background-color: gray;
  69. }
  70. </style>
  71. <script>
  72. function Submit() {
  73. let edits = document.querySelectorAll('.edit')
  74. let from = edits[0].value
  75. let to = edits[1].value
  76. let message = edits[2].value
  77. if(from == "" || to == "" || message == "") {
  78. return
  79. }
  80. let div = document.createElement('div')
  81. div.className = 'div1'
  82. div.innerHTML = from + " 对 " + to + "说:" + message
  83. let container = document.querySelector('.container')
  84. container.appendChild(div)
  85. for(i = 0; i < edits.length; i++) {
  86. edits[i].value = "";
  87. }
  88. }
  89. </script>
  90. </html>

发表评论

表情:
评论列表 (有 0 条评论,135人围观)

还没有评论,来说两句吧...

相关阅读