Blogger Information
Blog 35
fans 0
comment 0
visits 16767
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
留言板案例
手机用户311660634
Original
318 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. <body>
  10. <style>
  11. div {
  12. width: 300px;
  13. height: 500px;
  14. border: 3px solid black;
  15. display: grid;
  16. grid-template-rows: 1fr 30px;
  17. background-color: green;
  18. }
  19. div > input{
  20. background-color: rgb(71, 37, 174);
  21. }
  22. li {
  23. list-style: none;
  24. border: 1px solid red;
  25. margin: 5px;
  26. }
  27. </style>
  28. <div>
  29. <ul class="test">
  30. </ul>
  31. <input type="text" onkeydown="insertComment(this)" placeholder="请输入留言" autofocus>
  32. </div>
  33. <script>
  34. const insertComment = function(ele){
  35. // 按下回车键提交
  36. if(event.key === 'Enter'){
  37. // 非空判断
  38. if(ele.value.length === 0){
  39. alert('消息不能为空')
  40. // 重置焦点
  41. ele.focus()
  42. // 直接返回
  43. return false
  44. }
  45. const ul = document.querySelector('.test');
  46. ul.insertAdjacentHTML('beforeend', `<li>${ele.value}</li>`);
  47. ele.value = null
  48. }
  49. }
  50. </script>
  51. </body>
  52. </html>
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:可以, 效果实现的不错, 可以再尝试用css美化一下
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