abstract:<!doctype html><html> <head> <meta charset="UTF-8"> <meta name="Generator" content="baidu.com"> <meta name="A
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="Generator" content="baidu.com">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<!-- <link rel="stylesheet" type="text/css" href="css/">
<link rel="shortcut icon" type="image/x-icon" href="img/标题logo" -->
<script type="text/javascript" src="jquery-3.3.1.min.js"></script>
<title>jQuery 淡入淡出+在线客服</title>
<style type="text/css">
/* .box1{width:450px;height:130px;background:url(images/inputimg.jpg);border-radius:2%;text-align:center;vertical-align:middel;padding:30px 0px;}*/
.but1{width:200px;height:40px;border:none;background:#69A8DE;border-radius:15px;}
.box1{
width: 450px;
height: 650px;
background-color: lightskyblue;
margin: 30px auto;
color: #333;
box-shadow: 2px 2px 2px #808080
}
.box2{
width: 400px;
height: 500px;
border: 4px double green;
background-color: #efefef;
margin: 20px auto 10px;
}
ul {
list-style: none;
line-height: 2em;
/*border: 1px solid red;*/
overflow: hidden;
padding: 15px;
}
table {
width: 90%;
height:80px;
margin: auto;
}
textarea{
/*width: 300px;*/
border: none;
resize: none;
background-color: lightyellow;
}
button {
width: 60px;
height: 40px;
background-color: seagreen;
color: white;
border: none;
/*text-align: left;*/
}
button:hover {
cursor: pointer;
background-color: orange;
}
</style>
</head>
<body>
<button class="but1">在线客服</button>
<div class="box1">
<div contenteditable="true" class="box2">
<ul>
<li></li>
</ul>
</div>
<table>
<tr>
<td align="right"><textarea cols="50" rows="4" name="text"></textarea></td>
<td align="left"><button type="button" class="fs">发送</button></td>
</tr>
</table>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('.box1').hide()
$('.but1').click(function(){
$('.box1').fadeToggle(1100)
})
})
let btn = document.getElementsByClassName('fs')[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('客官:是不是忘记输入内容了~~');
return false;
}
let userComment = text.value;
text.value = '';
let li = document.createElement('li');
li.innerHTML = userComment;
let userPic = '<img src="http://www.ghost64.com/qqtupian/zixunImg/local/2017/11/24/1511494794752.jpg" width="40px" height="40px" style="border-radius:25%">'+' : ';
li.innerHTML = userPic + ' ' + userComment;
list.appendChild(li);
sum += 1;
setTimeout(function(){
let info = [
'喜欢一个人需要理由吗? 需要吗? 不需要吗?需要吗?',
'我那么喜欢你,你喜欢我一下会死啊?',
'不妨不妨,来日方长 。',
'既然这样,让我们立刻开始这段感情吧!',
'那个人样子好怪啊。 --我也看到了,他好像条狗啊。'
];
let temp = info[Math.floor(Math.random()*3)];
let reply = document.createElement('li');
let kefuPic = '<img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1552040575660&di=30c012122f03c6f2c9b6b12e7d7b1a7c&imgtype=0&src=http%3A%2F%2Fphotocdn.sohu.com%2F20120416%2FImg340646732.jpg" width="40" height="40" 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>
Correcting teacher:韦小宝Correction time:2019-03-09 09:12:02
Teacher's summary:写的还算是很不错的 没事要记得多去练习练习哦 可以考虑使用jQuery来把这个项目改写一下