HTML+CSS+JS在线客服对话框迷你版

一直都想写一个对话框,正好公司买了一个,就照着外观自己也写一个,每次写都会碰到意想不到的情况,通过解决这些情况,就很好的了解和学习了js知识。效果废话不多说,直接上代码HTML代码<!doctype html><html><head><meta charset="utf-8"><title>客服聊天</title><meta name="viewport" content="width=
摘要由CSDN通过智能技术生成

一直都想写一个对话框,正好公司买了一个,就照着外观自己也写一个,每次写都会碰到意想不到的情况,通过解决这些情况,就很好的了解和学习了js知识。

效果

废话不多说,直接上代码

HTML代码

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>于飞SEO客服聊天</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="stylesheet" href="styles/style.css">
<script src="https://cdn.staticfile.org/jquery/2.2.4/jquery.min.js"></script>
</head>
<body>
<div class="dialogue-wrapper">
    <div id="btn_open" class="dialogue-support-btn">
        <i class="dialogue-support-icon"></i>
        <i class="dialogue-support-line"></i>
        <span class="dialogue-support-text">联系客服</span>
    </div>
    <div class="dialogue-main">
        <div class="dialogue-header">
            <i id="btn_close" class="dialogue-close">></i>
            <div class="dialogue-service-info">
                <i 
  • 4
    点赞
  • 49
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 11
    评论
好的,这是一个简单的在线客服对话框HTMLCSSJS 代码示例: ``` <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>在线客服对话框</title> <style> body { margin: 0; padding: 0; font-family: Arial, sans-serif; } .chatbox { position: fixed; bottom: 20px; right: 20px; width: 300px; border: 1px solid #ccc; border-radius: 5px; background-color: #fff; box-shadow: 0px 0px 5px #ccc; z-index: 9999; } .chatbox-header { padding: 10px; border-bottom: 1px solid #ccc; background-color: #f0f0f0; border-radius: 5px 5px 0 0; } .chatbox-header h2 { margin: 0; font-size: 16px; font-weight: bold; color: #333; } .chatbox-body { padding: 10px; min-height: 200px; max-height: 400px; overflow-y: scroll; scroll-behavior: smooth; word-wrap: break-word; color: #555; font-size: 14px; } .chatbox-body p { margin: 0 0 10px 0; padding: 5px 10px; border-radius: 10px; background-color: #f0f0f0; max-width: 70%; } .chatbox-footer { padding: 10px; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; border-top: 1px solid #ccc; border-radius: 0 0 5px 5px; } .chatbox-footer input[type=text] { flex: 1; padding: 10px; border: none; border-radius: 5px; box-shadow: 0px 0px 5px #ccc; margin-right: 10px; font-size: 14px; } .chatbox-footer input[type=submit] { padding: 10px 20px; border: none; border-radius: 5px; background-color: #005ea5; color: #fff; font-size: 14px; cursor: pointer; transition: background-color 0.3s ease-in-out; } .chatbox-footer input[type=submit]:hover { background-color: #003e70; } </style> </head> <body> <div class="chatbox"> <div class="chatbox-header"> <h2>在线客服</h2> </div> <div class="chatbox-body"> <p>欢迎来到在线客服对话框!</p> </div> <div class="chatbox-footer"> <input type="text" placeholder="请输入您的问题..."> <input type="submit" value="发送"> </div> </div> <script> // 获取 DOM 元素 const chatbox = document.querySelector('.chatbox'); const input = chatbox.querySelector('input[type=text]'); const submitBtn = chatbox.querySelector('input[type=submit]'); const chatboxBody = chatbox.querySelector('.chatbox-body'); // 提交问题 function submitQuestion() { const question = input.value.trim(); if (question !== '') { // 发送问题 const questionP = document.createElement('p'); questionP.textContent = question; questionP.style.textAlign = 'right'; chatboxBody.appendChild(questionP); // 清空输入框 input.value = ''; // 模拟机器人回答 setTimeout(function() { // 机器人回答 const answer = '非常抱歉,目前无法回答您的问题。'; const answerP = document.createElement('p'); answerP.textContent = answer; chatboxBody.appendChild(answerP); }, 1000); } }; // 绑定按钮事件 submitBtn.addEventListener('click', submitQuestion); // 回车也可以提交问题 input.addEventListener('keydown', function(e) { if (e.key === 'Enter') { submitQuestion(); } }); </script> </body> </html> ``` 以上代码实现了一个简单的在线客服对话框,用户可以通过文本框输入问题,机器人会自动回复一些文本。你可以根据自己的需要修改样式和代码逻辑。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

于飞SEO

如果对你有帮助,就是我的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值