abstract:<html><meta charset="utf-8"><head> <style type="text/css"> ul{ list-style: none; padding: 15px; overflow: hidden} &n
<html>
<meta charset="utf-8">
<head>
<style type="text/css">
ul{ list-style: none; padding: 15px; overflow: hidden}
.div1{width: 450px;height: 650px; background: #ccc; box-shadow: 2px 2px 2px #808080;margin: 30px auto;}
.div2{ width: 400px; height: 500px; background: #efefef; border: 4px double green;
margin: 5px auto;}
h1{ text-align: center}
table{ width: 90%; height: 80px; margin: auto}
button:hover{ cursor: pointer}
</style>
</head>
<body>
<div class="div1">
<h1>在线客服</h1>
<div class="div2">
<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">发送</button></td>
</tr>
</table>
</div>
<script >
//获取页面元素
let btn = document.getElementsByTagName("button")[0];
console.log(btn);
let text = document.getElementsByName("text")[0];
console.log(text);
let list = document.getElementsByTagName("ul")[0];
console.log(list);
let sum = 0;
//添加点击事件,获取用户发送内容添加到ul
btn.onclick = function(){
//获取用户内容
if(text.value.length===0){
alert("您没有留言!");
return false;
}
let userComment = text.value;
text.value= "";
//创建一个li
let li = document.createElement("li");
li.innerHTML = userComment;
//创建用户头像
let userPic = "";
list.appendChild(li);
sum+=1;
//这是定时器,自动回复
setTimeout(function(){
let info = ["您好","您需要什么?","需要退货吗?"];
let temp = info[Math.floor(Math.random()*3)];
let reply = document.createElement("li");
let kefuPic = "";
reply.innerHTML=kefuPic+' <span style=color: "#ff6700;">'+temp+ '</span>';
list.appendChild(reply);
sum+=1;
},2000);
//清空窗口,并将计数器清零
if(sum>15){
list.innerHTML="";
sum=0;
}
}
</script>
</body>
</html>
Correcting teacher:查无此人Correction time:2019-04-23 13:29:19
Teacher's summary:完成的不错。更多的数据存储,等学习了php后,放到后端来存储。继续加油。