<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>DOM实战:模拟智能在线客服系统</title>
</head>
<style>
*{margin: 0;padding: 0;}
div:nth-child(1){
width: 450px;
height: 650px;
background: lightskyblue;
margin: 30px auto;
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: #efefef;
margin: 20px auto 10px;
overflow: hidden;
}
ul{
list-style-type: none;
line-height: 2em;
padding: 15px;
}
table{
width: 90%;
height: 80px;
margin: auto;
}
textarea{
border: none;
resize: none;
background: lightyellow;
float: left;
}
button{
width: 37px;
height: 60px;
float: right;
}
button:hover{
cursor: pointer;
background: orange;
}
</style>
<body>
<div>
<h2>在线客服</h2>
<div>
<ul>
<li></li>
</ul>
</div>
<table>
<td align="right"><textarea name="text" cols="50" rows="4"></textarea></td>
<td align="left"><button type="button">发送</button></td>
</table>
</div>
<script>
let btn = document.getElementsByTagName('button')[0];
let text = document.getElementsByName('text')[0];
let ul = document.getElementsByTagName('ul')[0];
// 计数器
let sum = 0;
</script>
</body>
</html>
总结:
1.先把局拉好,样式写好再开始写代码(样式就直接班老师的代码好了)
2.如果想操作页面上的元素,就要先获取到页面上的元素。我是直接按照老师的写法用标签获取元素
获取方法有:
getElementById、getElementsByClassName、getElementsByName、getElementsByTagName