Blogger Information
Blog 9
fans 0
comment 0
visits 3947
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
留言板---加自动回复
恒儿哥哥
Original
517 people have browsed it
  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. </head>
  9. <style>
  10. .main{
  11. display: grid;
  12. margin: auto;
  13. text-align: center;
  14. place-items:center;
  15. border: 1px solid salmon;
  16. }
  17. .box{
  18. display: grid;
  19. grid-template-columns: repeat(2,1fr);
  20. width: 90%;
  21. height: 50rem;
  22. }
  23. .box .box-1{
  24. text-align: left;
  25. width: 100%;
  26. }
  27. .box .box-2{
  28. text-align: right;
  29. width: 100%;
  30. }
  31. .bottom{
  32. display: grid;
  33. grid-template-columns: repeat(1,2fr);
  34. width: 100%;
  35. height: 5rem;
  36. border: 1px solid salmon;
  37. }
  38. .bottom-1 input{
  39. width: 99%;
  40. /* 取消边框样式 */
  41. border: none;
  42. /* 取消点击时候样式 */
  43. outline: none;
  44. height: 2rem;
  45. }
  46. .bottom button{
  47. float: right;
  48. width: 10rem;
  49. height: 100%;
  50. }
  51. li{
  52. list-style: none;
  53. }
  54. </style>
  55. <body>
  56. <div class="main">
  57. <h1>留言板---加自动回复</h1>
  58. <div class="box">
  59. <div class="box-1">
  60. <ul class="list-1"></ul>
  61. </div>
  62. <div class="box-2">
  63. <ul class="list-2"></ul>
  64. </div>
  65. </div>
  66. <div class="bottom">
  67. <div class="bottom-1">
  68. <input id="content" placeholder="请输入内容!!" onkeydown="addMsg(this)" autofocus value=""/>
  69. </div>
  70. <div class="bottom-2">
  71. <button onclick="sendMsg(this)"> 发送</button>
  72. </div>
  73. </div>
  74. </div>
  75. <script>
  76. function msg(){
  77. // 1. 获取显示留言的容器
  78. const ul = document.querySelector('.list-2');
  79. // 2. 判断用户留言是否为空\
  80. let content = document.querySelector('#content');
  81. if (content.value.length === 0) {
  82. alert('留言不能为空');
  83. content.focus();
  84. return false;
  85. }
  86. // 3. 添加一条新留言
  87. const li = document.createElement('li');
  88. li.textContent = content.value;
  89. li.innerHTML = content.value + '------<button onclick="del(this.parentNode)">删除</button>';
  90. ul.insertAdjacentElement('beforeend', li);
  91. console.log(ul);
  92. // 4. 将输入框中的前一条留言清空
  93. content.value = null;
  94. content.focus();
  95. setTimeout(function(){
  96. const ul = document.querySelector('.list-1');
  97. // 3. 添加一条新留言
  98. const li = document.createElement('li');
  99. arr = ['自动回复','你好','写的真不错','这个是一个数组','关闭当前网页'];
  100. let randomArr = arr[Math.floor(Math.random() * arr.length)];
  101. if(randomArr == '关闭当前网页'){
  102. if(confirm("您确定要关闭网页吗?")){
  103. window.opener=null;
  104. window.open('','_self');
  105. window.close();
  106. }
  107. }
  108. li.innerHTML = randomArr + '<button onclick="del(this.parentNode)">删除</button><br>';
  109. ul.insertAdjacentElement('beforeend', li);
  110. },1000);
  111. }
  112. function sendMsg(ele){
  113. msg();
  114. }
  115. function addMsg(ele) {
  116. if (event.key === 'Enter') {
  117. msg();
  118. }
  119. }
  120. // 删除
  121. function del(ele) {
  122. return confirm('是否删除?') ? ele.remove() : false;
  123. }
  124. // 页面加载时间
  125. window.onload=function(){
  126. const ul = document.querySelector('.list-1');
  127. // 3. 添加一条新留言
  128. const li = document.createElement('li');
  129. li.innerHTML ='欢迎访问-' + '<button onclick="del(this.parentNode)">删除</button><br>';
  130. ul.insertAdjacentElement('beforeend', li);
  131. }
  132. </script>
  133. </body>
  134. </html>

QQ截图20220405131915

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