<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
div{
width: 300px;
height: 400px;
border: 1px solid red;
}
</style>
</head>
<body>
<div></div>
小侯老师:<input type="text" placeholder="请输入内容">
<button>发送</button>
<script>
//1.获取元素
var oDiv = document.getElementsByTagName("div")[0];
var oInput = document.getElementsByTagName("input")[0];
var btn = document.getElementsByTagName("button")[0];
//2.给btn绑定点击事件
btn.onclick = function(){
//将input上的内容给div
//将原先的div内容拿过来 做拼接
oDiv.innerHTML = oDiv.innerHTML + "小侯老师:" + oInput.value + "<br>"
//清楚输入框的内容
oInput.value =""
}
</script>
</body>
</html>