在线客服案例完整

原创 2018-12-01 00:40:12 252
摘要:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>DOM实战模拟智能在线客服系统</title> <style type="text/css"> div:nth-child(1
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>DOM实战模拟智能在线客服系统</title>
<style type="text/css">
div:nth-child(1){
width: 450px;
height: 650px;

margin: 30px auto;
color: #333;

}
h2{
text-align: left;
margin-bottom: -10px;

}
.div2{
width: 100%;
height: 500px;


}
ul{
list-style: none;
line-height: 2em;
overflow: hidden;

}
table{
width: 90%;
height: 80px;
margin:auto;

}
textarea{

height: 40px;


}
button{
width: 50px;height: 46px;background-color:seagreen;color: white;border: none;
}
button:hover{
cursor: pointer;background-color:orange;
}
</style>
</head>
<body>
<div>
<div style="width: 100%;background-color:#000;height: 50px;line-height: 50px;">
<h2>&nbsp;<&nbsp;&nbsp;小冰</h2>
</div>
<div>
<ul>
<li></li>
</ul>
</div>
<table>
<tr>
<td><textarea name="text" cols="50" rows="4"></textarea></td>
<td><button>发送</button></td>
</tr>
</table>
</div>
<script type="text/javascript">
let btn = document.getElementsByTagName('button').item(0);
let text = document.getElementsByName('text').item(0);
let list = document.getElementsByTagName('ul')[0];
let sum =0;
btn.onclick = function  () {
// body... 
//alert(text.value);
if(text.value.length==0){
alert('没有输入内容哦');
return false;
}
let conner = text.value;//获取用户提交内容
text.value = '';//清空

let li = document.createElement('li');//创建li
let userPic = '<img src="pic/a.jpg" width="30" style="border-radius:50%">';
li.innerHTML =userPic+' '+conner;
// 将用户信息添加到ul框
list.appendChild(li);//
sum +=1;

//设置定时器
setTimeout(function(){

let info =[
'基辅大公',
'随机回复2',
'随机回复3',
'随机回复4..'
];
let temp = info[Math.floor(Math.random()*4)];
let reply = document.createElement('li');
let kefuPic = '<img src="pic/a.jpg" width="30" style="border-radius:50%">';
reply.innerHTML = kefuPic+' '+'<span style="color:red">'+temp+'</span>';
list.appendChild(reply);//
sum +=1;
},2000);
if (sum>10) {
list.innerHTML = '';
sum = 0;
}
}
</script>
</body>
</html>

GLWCPK1TQ}TW22RP{}@GN~N.png

批改老师:灭绝师太批改时间:2018-12-01 09:32:16
老师总结:作业完成的不错,要明白原理哦!继续加油!

发布手记

热门词条