摘要:<!DOCTYPE html><html><head> <title>DOM實戰(zhàn):模擬智能在線客服系統(tǒng)</title> <style type="text/css"> div:nth-child(1){ width: 450px; height: 650px; background-color
<!DOCTYPE html>
<html>
<head>
<title>DOM實戰(zhàn):模擬智能在線客服系統(tǒng)</title>
<style type="text/css">
div:nth-child(1){
width: 450px;
height: 650px;
background-color: lightskyblue;
margin: 30px auto;
color: #333;
box-shadow: 2px 2px 2px #808080;
}
h2{
text-align: center;
margin-bottom: -10px;
}
div:nth-child(2){
width: 400px;
height: 500px;
border:4px double green;
background-color: #efefef;
margin: 20px auto 10px;
}
ul{
list-style-type: none;
line-height: 2em;
overflow: hidden;
padding: 15px;
}
table{
width: 90%;
height: 80px;
margin: 0px auto;
}
textarea{
border: none;
resize: none;
background-color: lightyellow;
}
button{
width: 60px;
height: 40px;
background-color: seagreen;
color: white;
border:none;
}
button:hover{
cursor: pointer;
background: orange;
}
</style>
</head>
<body>
<div>
<h2>在線客服</h2>
<div>
<ul>
<li></li>
</ul>
</div>
<table>
<tr>
<td align="right"><textarea name="text" cols="50" rows="4"></textarea></td>
<td align="left"><button type="button">發(fā)送</button></td>
</tr>
</table>
</div>
<script type="text/javascript">
let btn = document.getElementsByTagName('button')[0];
let text = document.getElementsByName('text')[0];
let list = document.getElementsByTagName('ul')[0];
let sum = 0;
btn.onclick = function() {
if(text.value.length===0){
alert('發(fā)送信息不能為空');
return false;
}
let userComment = text.value;
text.value='';
let li = document.createElement('li');
li.innerHTML = userComment;
let userPic = '<img src="inc/1.jpg" width="30" style="border-radius:50%">';
li.innerHTML = userPic+''+userComment;
list.appendChild(li);
sum +=1;
//設(shè)置定時器2秒后自動回復(fù)
setTimeout(function(){
let info = [
'真煩人,有話快說,別耽誤我玩游戲',
'除了退貨退款,什么都可以問',
'說的是什么呢?沒聽懂',
'現(xiàn)在不方便,過會再來',
'投訴我的人多了,你算老幾。。。'
];
let temp = info[Math.floor(Math.random()*4)];
let reply = document.createElement('li');
let kefupPic='<img src="inc/2.jpg" width="30" style="border-radius:50%">';
reply.innerHTML=kefupPic+''+'<span style="color:red">'+temp+'</span>';
list.appendChild(reply);
sum +=1;
},2000);
if(sum>10){
list.innerHTML = '';
sum = 0;
}
}
</script>
</body>
</html>
批改老師:查無此人批改時間:2019-05-20 09:08:56
老師總結(jié):完成的不錯??头到y(tǒng)完成后,可以想想客戶與客戶之間的聊天系統(tǒng)。繼續(xù)加油。