在线客服自动回复

原创 2019-01-18 20:31:45 433
摘要:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>聊天信息列表</title> <style type="text/css"> .txt{width: 425px;h
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>聊天信息列表</title>
<style type="text/css">
.txt{width: 425px;height: 540px;padding:10px;margin:0px auto;border:1px solid #eee;border-radius: 15px;background: pink;}
.txt-1{border:1px solid #ff6b00;border-radius: 15px;margin-bottom: 20px;width: 420px;height: 400px;box-shadow: 3px 3px 3px #ccc;background: #fff;}
input{width: 300px;height: 30px;}
button{width: 80px;height: 36px;background:blue;color: #fff;}
button:hover{background: #ff6b00;}
li{list-style: none;}
</style>
</head>
<body>
<div>
<h3>在线客服</h3>
<div>
<ul>
<li></li>
</ul>
</div>
<input type="text">
<button>发送</button>
</div>
<script>
var ul=document.getElementsByTagName('ul')[0];
var input=document.getElementsByTagName('input')[0];
var btn=document.getElementsByTagName('button')[0];
var num=0;
btn.onclick=function(){
if(input.value ===''){
alert('请输入内容')
return false;
}
var li=document.createElement('li');
li.innerHTML="<img src='new!.gif' style='width:30px;border-radius:50%;border:1px solid red;'>"+'&nbsp;'+input.value;
ul.appendChild(li);
input.value="";
num +=1;
setTimeout (function(){
var info = [
    '真烦人,',
'除了退货,退款,咱们什么都可以聊',
'说啥?再说一遍',
'在我方便的时候再回复你吧~~',
'投诉我的人多了,你算老几~~~'
];
var temp = info[Math.floor(Math.random()*3)];
var reply = document.createElement('li');
var kefuPic = '<img src="zly.jpg" width="30" style="border-radius:50%;">';
reply.innerHTML = '<span style="color:red;">'+temp+'</span>'+''+kefuPic;

ul.appendChild(reply);
sum += 1;
},1000)
num +=1;
if(num >10){
ul.innerHTML="";
}
}
</script>
</body>
</html>

2019-01-18_202941.png

批改老师:天蓬老师批改时间:2019-01-19 09:10:05
老师总结:这个案例,其实就是一个经典的ToDOlist的案例, 可以学习到dom的基本的操作

发布手记

热门词条