博客列表 >留言板功能与客服自动回复

留言板功能与客服自动回复

新手1314
新手1314原创
2022年04月06日 14:57:48418浏览

留言板

HTML

  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. <div class="head">
  11. <p>留言板</p>
  12. <input type="text" onkeydown="addMsg(this)" name="" id="" placeholder="请输入内容" autofocus />
  13. <ul class="list">
  14. <p class="liu">留言内容</p>
  15. <ul class="rest"></ul>
  16. </ul>
  17. </div>
  18. <style>
  19. .head {
  20. width: 400px;
  21. height: 400px;
  22. margin: auto;
  23. border: 1px solid #000;
  24. background-color: bisque;
  25. border-radius: 50px;
  26. }
  27. .head p {
  28. margin-left: 170px;
  29. }
  30. .head input {
  31. margin-left: 100px;
  32. border-radius: 20px;
  33. }
  34. .head .rest {
  35. margin-left: -40px;
  36. width: 100%;
  37. height: 270px;
  38. border-top: 1px solid #000;
  39. border-radius: 20px;
  40. list-style: none;
  41. }
  42. .head .liu {
  43. margin-left: 120px;
  44. }
  45. </style>
  46. <script>
  47. function addMsg(ele) {
  48. if (event.key === "Enter") {
  49. let ul = document.querySelector(".rest");
  50. if (ele.value.trim().length === 0) {
  51. alert("留言不能为空");
  52. ele.fouse();
  53. return;
  54. }
  55. const li = document.createElement("li");
  56. const buttom = document.createElement("button");
  57. li.innerHTML = ele.value + '<button style="margin-left: 200px;background-color: blueviolet;color: #fff;border-radius: 15px;" onclick="del(this.parentNode)">删除</button>';
  58. ul.insertAdjacentElement("afterbegin", li);
  59. ele.value = null;
  60. }
  61. }
  62. function del(ele) {
  63. return confirm("是否删除?") ? ele.remove() : false;
  64. }
  65. </script>
  66. </body>
  67. </html>

客服自动回复

HTML

  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="//at.alicdn.com/t/font_3280782_jb6l34uhw5.css" />
  9. </head>
  10. <body>
  11. <style>
  12. .list {
  13. margin-top: 100px;
  14. margin-left: 700px;
  15. width: 400px;
  16. height: 600px;
  17. border: 3px solid blue;
  18. border-radius: 30px;
  19. }
  20. .head {
  21. background-color: blue;
  22. color: #fff;
  23. height: 50px;
  24. text-align: center;
  25. border-radius: 25px 25px 0 0;
  26. }
  27. .rest {
  28. height: 30px;
  29. background-color: #999;
  30. text-align: center;
  31. }
  32. .last {
  33. margin-top: 0px;
  34. border-top: 2px solid #999 !important;
  35. }
  36. .last input {
  37. outline: none;
  38. border: none;
  39. font-size: 18px;
  40. margin-top: 10px;
  41. width: 98%;
  42. }
  43. .bu {
  44. margin-top: 50px;
  45. margin-left: 290px;
  46. }
  47. .bu button {
  48. background-color: blue;
  49. color: #fff;
  50. border-radius: 10px;
  51. width: 100px;
  52. height: 30px;
  53. }
  54. .o .time {
  55. margin-left: 120px;
  56. }
  57. .o {
  58. height: 370px;
  59. }
  60. .o .ul1,
  61. .o .ul2 {
  62. list-style: none;
  63. }
  64. .iconfont {
  65. font-size: 34px;
  66. }
  67. .two {
  68. margin-left: 250px;
  69. }
  70. </style>
  71. <div class="list">
  72. <div class="head">PHP中文网</div>
  73. <div class="rest">客服:php中文网新手1314即将为您服务</div>
  74. <div class="o">
  75. <div class="time">2022-4-4 16:01:30</div>
  76. <ul class="ul1"></ul>
  77. </div>
  78. <div class="last">
  79. <input type="text" onkeydown="addMsg(this)" placeholder="请输入,按Enter直接发送消息" />
  80. <div class="bu"><button>发送</button></div>
  81. </div>
  82. </div>
  83. <script>
  84. function addMsg(ele) {
  85. if (event.key === "Enter") {
  86. const ul = document.querySelector(".ul1");
  87. if (ele.value.trim().length === 0) {
  88. alert("不能输入空消息");
  89. ele.focus();
  90. return false;
  91. }
  92. const li = document.createElement("li");
  93. li.className = "two";
  94. li.innerHTML = ele.value + ' :<img src="user.jpg" alt="" style="height: 42%;width: 42%;">';
  95. // ul.insertAdjacentElement("afterbegin", li);
  96. ul.append(li);
  97. ele.value = null;
  98. setTimeout(function () {
  99. const ul1 = document.querySelector(".ul1");
  100. const info = ["你好", "欢迎光临", "你慢走", "有空再来"];
  101. const tmp = info[Math.floor(Math.random() * 4)];
  102. const replay = document.createElement("li");
  103. replay.innerHTML = '<span class="iconfont icon-kefuyouxian"></span>:' + tmp;
  104. ul1.append(replay);
  105. sum += 1;
  106. }, 2000);
  107. }
  108. }
  109. </script>
  110. </body>
  111. </html>
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议