Blogger Information
Blog 38
fans 0
comment 0
visits 18506
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
留言板功能
Blackeye
Original
579 people have browsed it

在线演示

demo

  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. <link rel="stylesheet" href="hw.css" />
  9. <link rel="stylesheet" href="static/css/iconfont.css" />
  10. </head>
  11. <body>
  12. <!-- 演示区域 -->
  13. <div class="showArea">
  14. <!-- 在线客服头部 -->
  15. <div class="title">
  16. <button onclick="back()" title="返回">&lt;</button>
  17. <span>在线客服</span>
  18. </div>
  19. <div class="displayArea">
  20. <!-- 1.留言板图标 -->
  21. <!-- 2.图标选中颜色变化 -->
  22. <div class="msgIcon iconfont icon-kefu" onclick="showMsg()"></div>
  23. <!-- 3.设置留言板样式 -->
  24. <div class="msgDisplay">
  25. <!-- 展示客户问题 -->
  26. <div class="msgShow">
  27. <ul class="msgShowList">
  28. </ul>
  29. </div>
  30. <!-- 客户输入文本框 -->
  31. <div class="msgInput">
  32. <textarea
  33. name="inputData"
  34. id="inputData"
  35. onkeydown="submitMsg(this)"
  36. placeholder="请输入,按Enter直接发送消息"
  37. autofocus
  38. ></textarea>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. <script>
  44. function showMsg() {
  45. const msgIcon = document.querySelector(".msgIcon");
  46. const title = document.querySelector(".title");
  47. const msgDisplay = document.querySelector(".msgDisplay");
  48. msgIcon.style.display = "none";
  49. title.style.display = "block";
  50. msgDisplay.style.display = "grid";
  51. }
  52. function back() {
  53. const msgIcon = document.querySelector(".msgIcon");
  54. const title = document.querySelector(".title");
  55. const msgDisplay = document.querySelector(".msgDisplay");
  56. title.style.display = "none";
  57. msgDisplay.style.display = "none";
  58. msgIcon.style.display = "block";
  59. }
  60. // 1. 独立完成留言板功能,要求使用CSS进行页面美化
  61. // 2. (选做)将留言板功能升级为自动客服回复(定时器实现)
  62. function submitMsg(ele) {
  63. if (event.key === "Enter") {
  64. // 判断是否输入为空
  65. if (ele.value.trim() !== "") {
  66. const ul = document.querySelector(".msgShowList");
  67. const li = document.createElement("li");
  68. li.innerHTML =
  69. `<p>
  70. <img src="static/img/userProfilePicture.jpeg">` +
  71. `<span>${ele.value.trim()}</span>
  72. </p>`;
  73. ul.insertAdjacentElement("beforeEnd", li);
  74. webpageMsg(ele.value.trim());
  75. } else {
  76. alert("输入有误,请重新输入!");
  77. }
  78. event.preventDefault();
  79. ele.value = "";
  80. ele.focus();
  81. }
  82. }
  83. function webpageMsg(lo) {
  84. const ul = document.querySelector(".msgShowList");
  85. const li = document.createElement("li");
  86. li.innerHTML = `<span>对方正在输入</span>`;
  87. ul.insertAdjacentElement("beforeEnd", li);
  88. setTimeout(function () {
  89. if(lo==="天王盖地虎"){
  90. li.innerHTML = `<p>
  91. <img src="static/img/webProfilePicture.jpg">` +
  92. `<span>小鸡炖蘑菇</span>
  93. </p>`;
  94. li.className="userRight";
  95. ul.replaceChild(li,ul.lastChild);
  96. }else if(lo==="12345"){
  97. li.innerHTML = `<p>
  98. <img src="static/img/webProfilePicture.jpg">` +
  99. `<span>上山打老虎</span>
  100. </p>`;
  101. li.className="userRight";
  102. ul.replaceChild(li,ul.lastChild);
  103. }
  104. else{
  105. li.innerHTML = `<p>
  106. <img src="static/img/webProfilePicture.jpg">` +
  107. `<span>口令不对再想想</span>
  108. </p>`;
  109. li.className="userRight";
  110. ul.replaceChild(li,ul.lastChild);
  111. }
  112. }, 1000);
  113. }
  114. </script>
  115. </body>
  116. </html>
  1. *{
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. a{
  7. text-align: none;
  8. color:black;
  9. }
  10. ul{
  11. list-style-type: none;
  12. }
  13. body{
  14. background-color: azure;
  15. }
  16. .showArea{
  17. width: 601px;
  18. height: 600px;
  19. margin: auto;
  20. display: grid;
  21. grid-template-rows: 40px 1fr;
  22. border-radius: 10px;
  23. background-color: rgb(15, 127, 219);
  24. }
  25. .showArea .title{
  26. width: 601px;
  27. text-align: center;
  28. background-color: rgba(175, 33, 226, 0.661);
  29. padding: 3px;
  30. border-radius: 10px 10px 0 0;
  31. display: none;
  32. }
  33. .showArea .title button{
  34. border-radius: 5px;
  35. outline: none;
  36. border: none;
  37. background-color: white;
  38. color: #BBB;
  39. margin-right: 10px;
  40. padding: 5px;
  41. }
  42. .showArea .title button:hover{
  43. cursor: pointer;
  44. background-color: coral;
  45. color: white;
  46. }
  47. .showArea .title>span{
  48. letter-spacing: 5px;
  49. font-size: 25px;
  50. color:white;
  51. }
  52. .displayArea{
  53. position: relative;
  54. }
  55. .displayArea .msgIcon{
  56. width: 70px;
  57. height: 70px;
  58. background-color: white;
  59. border-radius: 50%;
  60. font-size: 65px;
  61. text-align: center;
  62. color: #e1e1e1;
  63. position: absolute;
  64. margin-top: 300px;
  65. right: 0;
  66. margin-right: 10px;
  67. /* 测试先关闭 */
  68. /* display: none; */
  69. }
  70. .displayArea .msgIcon:hover{
  71. cursor: pointer;
  72. color:coral;
  73. }
  74. .msgDisplay{
  75. border: 0.5px solid black;
  76. border-radius: 0 0 10px 10px;
  77. display: grid;
  78. grid-template-rows: 400px 1fr;
  79. display: none;
  80. }
  81. .msgDisplay .msgShow{
  82. background-color: #fefefe;
  83. }
  84. .msgDisplay .msgInput textarea{
  85. padding: 10px;
  86. outline: none;
  87. border: none;
  88. border-top: 1px solid #eee;
  89. border-radius: 0 0 10px 10px;
  90. resize: none;
  91. width: 600px;
  92. height: 160px;
  93. }
  94. .msgDisplay .msgShow{
  95. padding: 10px;
  96. overflow: auto;
  97. }
  98. .msgDisplay .msgShow img{
  99. width: 50px;
  100. height: 50px;
  101. vertical-align:middle;
  102. border-radius: 10px;
  103. }
  104. .msgDisplay .msgShow ul li{
  105. margin-top: 5px;
  106. }
  107. .msgDisplay .msgShow ul p{
  108. width: 300px;
  109. background-color: #eee;
  110. border-radius: 10px;
  111. }
  112. .msgDisplay .msgShow ul li>span{
  113. display: flex;
  114. place-content: center;
  115. }
  116. .msgDisplay .msgShow .userRight{
  117. display: flex;
  118. place-content: flex-end;
  119. }
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!