批改状态:合格
老师批语:
实例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style type="text/css">
div{
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:auto;
}
textarea{
resize:none;
border:none;
background-color:lightyellow;
}
button{
width:60px;
height:40px;
background-color:seagreen;
color:#fff;
border:none;
}
</style>
<title>Document</title>
</head>
<body>
<div>
<h2>在线客服</h2>
<div contenteditable="true">
<ul>
<li></li>
</ul>
</div>
<table>
<tr>
<td><textarea cols="50 " rows="" name="text"></textarea></td>
<td><button>发送</button></td>
</tr>
</table>
</div>
<script type="text/javascript">
//获取页面中的按钮,文本域,对话窗口
var btn=Document.getElementsByTagName('button')[0]
var text=Document.getElementsByName('text')[0]
var list=Document.getElementsByTagName('ul')[0]
btn.onclick=function(){
if(text.value.length == 0){
alert('您好,写点东西再点发送')
return false
}
}
var userComment=text.value
text.value=''
//创建新节点
var li=Document.createElement('li')
li.innerHTML = userComment
var userPic = '<img src="../images/peter.jpg" width="30" style="border-radius:50%">'
li.innerHTML = userPic+userComment
//将新节点插入到对话列表中
list.appendChild(li)
sum += 1
setTimeout(function(){
var info = ['你好烦人呀,本姑娘好累,不知道怜香惜玉吗?','除了退货,退款,维修,什么问题都可以问','啥事呀,我的帅哥哥']
var temp = info[Math.floor(Math.random()*3)]
//取1-5之间的一个整数:Math.floor(Math.random()*6 + 1)
var reply = document.createElement('li')
var kefuPic = '<img src="../images/zly.jpg" width="30" style="border-radius:50%;">'
// reply.innerHTML = '你有啥事呀,我的帅哥哥' +kefuPic
reply.innerHTML = kefuPic + '<span style="color:red">'+temp+'</span>'
// reply.style.float = 'right'
list.appendChild(reply)
sum += 1
},2000)
if (sum > 10) {
list.innerHTML = ''
sum = 0
}
</script>
</body>
</html>
运行实例 »
点击 "运行实例" 按钮查看在线实例


Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号