客服自动回复

Original 2019-04-15 22:11:40 251
abstract:<!DOCTYPE html> <html> <head> <title>智能在线客服系统</title> <style type="text/css"> div:nth-child(1){width: 450px; height: 650px;
<!DOCTYPE html>
<html>
<head>
	<title>智能在线客服系统</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:none;
			line-height: 2em;
			overflow: hidden;
			padding: 15px;

		}
		table{
			width: 90%;
			height: 80px;
			margin: 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-color: orange;
		}

	</style>
</head>
<body>
<div>
	<h2>在线客服</h2>
	<div contenteditable="true">
		<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 type="text/javascript">
	var btn=document.getElementsByTagName('button')[0];
		let text = document.getElementsByName('text')[0];
	var list=document.getElementsByTagName('ul')[0];
	var sum=0;

	btn.onclick=function(){
		//创建一个新的标签li;
		var li=document.createElement('li');
		var	userCommer=text.value;
		 if (userCommer.length ==0) {
		 	alert('请输入想说的话');
			return false;
		}
		var me="我说:";
		li.innerHTML=me+userCommer
		list.appendChild(li);
		text.value ='';
		sum += 1;

		//自动回复
		setTimeout(function(){
			var info=[
			'不是我',
			'真的不是我',
			'都说了住的不是我',
			'好吧,其实不是我'
			];
			//随机回复;
			//随机数向下取整;
			//(0-1的随机数)*4=0-4的随机数,然后在向下取整;
			var temp=Math.floor(Math.random()*4)
			//得到随机出现的对话;
			var speak=info[temp];
			//在声明一个标签li;
			var lis=document.createElement('li');
			var people='客服说:';
			//改变lis里面的内容;
			lis.innerHTML=people+'<span style="color:red">'+speak+'</span>';
			// 在ul里面添加lis'
			list.appendChild(lis);
			sum += 1;
		},2000)

		if (sum>10) {
			list.innerHTML="";
			sum=0;
		}


	}

</script>
</body>
</html>


Correcting teacher:查无此人Correction time:2019-04-16 09:33:34
Teacher's summary:完成的不错。以后学了php,就可以从数据库拿回复话了。像京东那样机器回复。

Release Notes

Popular Entries