????:總結(jié):這個(gè)案例很簡(jiǎn)單,但是骨架都有。簡(jiǎn)單易懂,截圖:代碼:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>DOM實(shí)戰(zhàn):模擬智能在線客服系統(tǒng)</title><style type="text
總結(jié):
這個(gè)案例很簡(jiǎn)單,但是骨架都有。簡(jiǎn)單易懂,
截圖:
代碼:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>DOM實(shí)戰(zhàn):模擬智能在線客服系統(tǒng)</title>
<style type="text/css">
div:nth-child(1){
width: 450px;
height: 650px;
background: lightskyblue;
color:#333;
margin:30px auto;
box-shadow: 2px 2px 2px #808080;
}
h2{
text-align: center;
margin-bottom: -10px;
}
div:nth-child(2){
width:400px;
height:500px;
background: #efefef;
border: 4px double green;
margin: 20px auto 10px;
}
ul{
list-style:none;
padding:15px;
line-height: 2em;
}
table{
width:90%;
height:80px;
margin:0 auto;
}
textarea{
width:280px;
height:56px;
overflow: hidden;
border:none;
resize:none;
padding:2px;
background-color: lightyellow;
}
button{
width:80px;
height:59px;
line-height: 60px;
background-color:seagreen;
border:none;
color:white;
}
button:hover{
cursor:pointer;
background-color:orange;
}
</style>
</head>
<body>
<div>
<h2>在線客服</h2>
<div contenteditable="true">
<ul>
<li></li>
</ul>
</div>
<table>
<tr>
<td align="right"><textarea name="text" id="" cols="30" rows="5"></textarea></td>
<td align="right"><button type="button">發(fā)送</button></td>
</tr>
</table>
</div>
<script>
//獲取到頁(yè)面中的按鈕,文本域,對(duì)話內(nèi)容區(qū)
let btn = document.getElementsByTagName('button')[0];
let text = document.getElementsByName('text')[0];
let list = document.getElementsByTagName('ul')[0];
let sum = 0;
//添加按鈕點(diǎn)擊事件,獲取用戶數(shù)據(jù)并推送到對(duì)話窗口中
btn.onclick = function(){
// alert(text.value);
if(text.value.length === 0){
alert('不能發(fā)送空內(nèi)容,小辣椒');
return false;
}
let userComment = text.value;
text.value = "";
let userPic = '<img src="inc/peter.jpg" width="30px" style="border-radius:50%">';
let li = document.createElement('li');
li.innerHTML = userPic + " " + userComment;
list.appendChild(li);
sum++;
setTimeout(function(){
let info = [
'真煩人,有話快說(shuō),別耽誤我玩抖音',
'除了退貨,退款,咱們什么都可以聊',
'說(shuō)啥,本姑娘怎么聽不懂呢?再說(shuō)一遍',
'在我方便的時(shí)候再回復(fù)你吧~~',
'投訴我的人多了,你算老幾~~~'
];
//Math.random() 函數(shù)返回一個(gè)浮點(diǎn), 偽隨機(jī)數(shù)在范圍[0,1)
let kefuTemp = info[Math.floor(Math.random()*5)];
let li = document.createElement('li');
let kefuPic = '<img src="inc/zly.jpg" width="30px" style="border-radius:50%">';
li.innerHTML = kefuPic + " " + kefuTemp;
list.appendChild(li);
sum++;
}, 1000);
if(sum>10){
list.innerHTML = "";
sum = 0;
}
}
</script>
</body>
</html>
?? ???:查無(wú)此人?? ??:2019-03-18 09:39:11
???? ??:做的還不錯(cuò),就是客服說(shuō)話挺沖的,繼續(xù)加油。