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="static/css/reset.css" />
  9. <link rel="stylesheet" href="static/css/main.css" />
  10. </head>
  11. <body>
  12. <!-- 头部 -->
  13. <header>
  14. <a href="">留言板</a>
  15. <a href="">关于我们</a>
  16. </header>
  17. <!-- 主体部分 -->
  18. <main>
  19. <div class="box">
  20. <textarea onkeydown="addMsg(this)" placeholder="请输入留言内容"></textarea>
  21. <button onclick="clickbutton()">发表留言</button>
  22. </div>
  23. <a href=""></a>
  24. <h2>留言列表</h2>
  25. <ul class="content-list"></ul>
  26. </main>
  27. <!-- 底部客服 -->
  28. <footer>
  29. <div class="kf">
  30. <a href="javascript:;">
  31. <img src="static/image/img-info24.svg" alt="" />
  32. </a>
  33. <span>有问题请点我哦!</span>
  34. <a href="javascript:;" onclick="showkf()">
  35. <img src="static/image/to-maxWindow.svg" alt="" />
  36. </a>
  37. </div>
  38. <div class="kf_box" style="display: none">
  39. <!-- 客服标题 -->
  40. <div class="title">
  41. <span>客服系统</span>
  42. <a href="JavaScript:;" onclick="closekf()">
  43. <img src="static/image/to-minWindow.svg" alt="" />
  44. </a>
  45. </div>
  46. <!-- 客服界面主体 -->
  47. <div class="kf_main">
  48. <div class="msg">
  49. <p class="left">请问你有什么问题吗?</p>
  50. </div>
  51. <div contenteditable="true" placeholder="请输入文字" class="text_area"></div>
  52. <button onclick="addMsg_kf()">发送</button>
  53. </div>
  54. </div>
  55. </footer>
  56. <script>
  57. // 显示客服界面
  58. function showkf() {
  59. let kefu = document.querySelector('.kf_box');
  60. kefu.style.display = 'block';
  61. }
  62. // 关闭客服界面
  63. function closekf() {
  64. let kefu = document.querySelector('.kf_box');
  65. kefu.style.display = 'none';
  66. }
  67. //把用户输入的问题发送到聊天界面
  68. function addMsg_kf() {
  69. let msg = document.querySelector('.kf_box .kf_main .text_area');
  70. let msgBox = document.querySelector('.kf_box .kf_main .msg');
  71. if (msg.innerText.trim().length === 0) {
  72. console.log('消息为空');
  73. msg.innerText = null;
  74. msg.focus();
  75. } else {
  76. const p = document.createElement('p');
  77. p.className = 'right';
  78. p.textContent = msg.innerText;
  79. msgBox.insertAdjacentElement('beforeEnd', p);
  80. msg.innerText = null;
  81. msg.focus();
  82. }
  83. }
  84. //定时器监控消息
  85. setInterval('monitoring()', 1000);
  86. let msgNumber = 1;
  87. function monitoring() {
  88. // let rightMsg = document.querySelector('.kf_box .kf_main .msg .right');
  89. let rightMsg = document.querySelector('.kf_box .kf_main .msg');
  90. console.log(rightMsg.children.length);
  91. console.log('当前检测消息数量:' + msgNumber);
  92. if (rightMsg.children.length > msgNumber) {
  93. console.log('有新消息');
  94. console.log(rightMsg.innerText);
  95. const p = document.createElement('p');
  96. p.className = 'left';
  97. p.textContent = '你好我是客服系统';
  98. rightMsg.insertAdjacentElement('beforeEnd', p);
  99. msgNumber = msgNumber + 2;
  100. } else {
  101. console.log('暂时没有新消息');
  102. }
  103. }
  104. // 1.获取文本框的内容
  105. // 2.判断文本框留言内容是否为空
  106. // 3.有内容则把留言添加到列表中,为空则返回
  107. // 4.将输入框中的前一条留言清空
  108. // 5.焦点重置
  109. function clickbutton() {
  110. let ul = document.querySelector('.content-list');
  111. let input = document.querySelector('.box textarea');
  112. if (input.value.trim().length === 0) {
  113. alert('内容为空,请输入留言内容');
  114. } else {
  115. // 将内容添加到列表中
  116. console.log(input.value);
  117. // 创建一个li标签,并添加进去
  118. const li = document.createElement('li');
  119. li.innerHTML = input.value + '<button onclick = "del(this.parentNode)">删除</button><hr/>';
  120. ul.insertAdjacentElement('afterBegin', li);
  121. input.value = null;
  122. input.focus();
  123. }
  124. }
  125. function addMsg(ele) {
  126. // console.log(event.key);
  127. if (event.key === 'Enter') {
  128. let ul = document.querySelector('.content-list');
  129. let input = document.querySelector('.box textarea');
  130. if (input.value.trim().length === 0) {
  131. alert('内容为空,请输入留言内容');
  132. } else {
  133. // 将内容添加到列表中
  134. console.log(input.value);
  135. // 创建一个li标签,并添加进去
  136. const li = document.createElement('li');
  137. li.innerHTML = input.value + '<button onclick = "del(this.parentNode)">删除</button><hr/>';
  138. ul.insertAdjacentElement('afterBegin', li);
  139. input.value = null;
  140. //多行文本回车不换行
  141. event.preventDefault();
  142. ele.focus();
  143. }
  144. }
  145. }
  146. function addStyle(value, tag) {}
  147. function del(ele) {
  148. if (confirm('是否删除?')) {
  149. ele.remove();
  150. }
  151. }
  152. </script>
  153. </body>
  154. </html>

main.css

  1. /* 头部 */
  2. header {
  3. display: flex;
  4. height: 60px;
  5. background-color: #f8f8f8;
  6. justify-content: space-around;
  7. align-items: center;
  8. }
  9. /* 设置留言板字体大小 */
  10. header > a:first-of-type {
  11. font-size: 25px;
  12. color: #858585;
  13. }
  14. /* 主体部分 */
  15. /* 留言板整体居中 */
  16. main .box {
  17. display: flex;
  18. flex-flow: column nowrap;
  19. align-items: center;
  20. margin: 20px;
  21. }
  22. /* 设置一下文本输入框样式 */
  23. main .box textarea {
  24. border: 1px solid #ccc;
  25. border-radius: 5px;
  26. font-size: 20px;
  27. padding: 5px;
  28. width: 800px;
  29. height: 120px;
  30. }
  31. /* 设置按钮样式 */
  32. main .box button {
  33. width: 800px;
  34. height: 40px;
  35. margin: 20px;
  36. background-color: #0088ff;
  37. border: none;
  38. color: white;
  39. margin: 20px 2px;
  40. cursor: pointer;
  41. border-radius: 5px;
  42. }
  43. main .box button:hover {
  44. background-color: #8eb1cf;
  45. }
  46. main .box button:active {
  47. background-color: red;
  48. }
  49. /* 留言列表 */
  50. main h2 {
  51. position: relative;
  52. left: calc((100vw - 800px) / 2);
  53. }
  54. /* 留言列表设置 */
  55. main ul {
  56. position: relative;
  57. left: calc((100vw - 800px) / 2);
  58. }
  59. /* 设置li的距离 */
  60. main ul li {
  61. margin: 20px 0;
  62. width: 800px;
  63. }
  64. /* 设置一下按钮的样式 */
  65. main ul li button {
  66. border-radius: 5px;
  67. outline: none;
  68. border-width: 0px;
  69. background-color: #ffffff;
  70. color: blue;
  71. margin-left: 20px;
  72. padding: 5px;
  73. cursor: pointer;
  74. }
  75. main ul li button:active {
  76. color: red;
  77. }
  78. /* 在线客服 */
  79. footer .kf {
  80. background-color: #1798fc;
  81. width: 225px;
  82. height: 42px;
  83. display: flex;
  84. justify-content: space-between;
  85. align-items: center;
  86. /* 固定到页面右下角 */
  87. position: fixed;
  88. right: 0;
  89. bottom: 0;
  90. }
  91. /* 设置客服提示字体颜色 */
  92. footer .kf span {
  93. color: #ffffff;
  94. }
  95. /* 设置a标签样式 */
  96. footer .kf > a {
  97. background-color: #127aca;
  98. width: 42px;
  99. height: 100%;
  100. padding: 10px;
  101. }
  102. /* 第二个a标签覆盖上面的颜色 */
  103. footer .kf > a:last-of-type {
  104. background-color: #1798fc;
  105. }
  106. footer .kf > a:last-of-type:hover {
  107. background-color: #1589e2;
  108. }
  109. /* 客服标题样式 */
  110. footer .kf_box {
  111. width: 360px;
  112. height: 576px;
  113. box-shadow: -2px -2px 0 0 #eeeeee;
  114. position: fixed;
  115. right: 0;
  116. bottom: 0;
  117. background-color: #fff;
  118. z-index: 99;
  119. }
  120. /* 客服标题加一下背景 */
  121. footer .kf_box .title {
  122. background-color: #1798fc;
  123. height: 36px;
  124. display: flex;
  125. justify-content: space-between;
  126. align-items: center;
  127. }
  128. /* 客服标题字体颜色 */
  129. footer .kf_box .title span {
  130. color: #ffffff;
  131. padding: 5px;
  132. }
  133. /* 客服界面主体布局 */
  134. footer .kf_main {
  135. /* width: 900px; */
  136. /* height: 676px; */
  137. /* border: 1px solid; */
  138. display: flex;
  139. flex-direction: column;
  140. }
  141. /* 设置聊天界面高度 */
  142. footer .kf_main .msg {
  143. height: 350px;
  144. padding: 10px;
  145. }
  146. /* 设置输入框样式 */
  147. footer .kf_main .text_area {
  148. border-top: 1px solid;
  149. color: #3a3c4c;
  150. height: 140px;
  151. outline: none;
  152. padding: 5px;
  153. }
  154. /* 设置发送按钮样式 */
  155. footer .kf_main button {
  156. width: 50px;
  157. height: 25px;
  158. outline: none;
  159. background-color: #1798fc;
  160. color: #fff;
  161. border-radius: 5px;
  162. border: none;
  163. place-self: end;
  164. margin: 10px;
  165. cursor: pointer;
  166. }
  167. /* 设置发送按钮鼠标悬停颜色 */
  168. footer .kf_main button:hover {
  169. background-color: #5da9e4;
  170. }
  171. footer .kf_main .msg {
  172. display: flex;
  173. flex-direction: column;
  174. }
  175. /* 设置用户发的消息样式 */
  176. footer .kf_main .msg .right {
  177. place-self: end;
  178. background-color: #1798fc;
  179. color: #fff;
  180. padding: 5px;
  181. margin: 5px 0px;
  182. border-radius: 5px;
  183. }
  184. /* 设置客服回的消息样式 */
  185. footer .kf_main .msg .left {
  186. place-self: start;
  187. background-color: #e90e33;
  188. color: #fff;
  189. padding: 5px;
  190. margin: 5px 0px;
  191. border-radius: 5px;
  192. }

reset.css

  1. /* 页面元素样式初始化 */
  2. * {
  3. margin: 0;
  4. padding: 0;
  5. box-sizing: border-box;
  6. }
  7. /* 去掉a链接的文本装饰 */
  8. a {
  9. text-decoration: none;
  10. color: #555;
  11. }
  12. /* 去掉li标签的标记的点 */
  13. li {
  14. list-style: none;
  15. }
  16. input,
  17. textarea {
  18. outline-style: none;
  19. }

更多相关文章

  1. android判断网络连接状态
  2. 设置android默认属性
  3. android 网络图片查看器
  4. Android(安卓)Activity设置全屏
  5. android:程序中安装APK方法
  6. Android(安卓)常见问题收集 (持续更新)
  7. Android(安卓)Animation动画详解
  8. android 为TextView的部分文字设置超链接样式并监听点击事件
  9. Android(安卓)Studio设置gradle代理

随机推荐

  1. Android Universal Image Loader 源码分
  2. Android中ListView的addFooterView不显示
  3. getprop 获取android系统属性
  4. Android安卓51个开源代码
  5. 安卓(Android)实现选择时间功能
  6. Android 权限汇总
  7. android 应用程序Activity之间数据传递与
  8. 点击LinearLayout使用selector改变TextVi
  9. Android Studio 第五十六期 - Android之
  10. ListActivity setContentView 错误