说明:为不完整版,后续学习后会更新
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>发送消息</title>
<style type="text/css">
#screen{
width: 240px;
height: 200px;
border: 5px solid #ccc;
padding: 10px;
}
#strong1{cursor: pointer;}
</style>
<script type="text/javascript">
window.onload = function(){
var oScreen = document.getElementById('screen');
var oStrong = document.getElementById('strong1');
var oText = document.getElementById('text1');
var oBtn = document.getElementById('btn1');
oBtn.onclick = function(){
oScreen.innerHTML += oStrong.innerHTML + ':' + oText.value + '<br>';
oText.value = '';
}/*a=a+b; 相当于 a+=b;*/
oStrong.onclick = function(){
if(oStrong.innerHTML == '张三'){oStrong.innerHTML = '王四';}
else{oStrong.innerHTML = '张三';} /*名字变换*/
}
}
</script>
</head>
<body>
<div id="screen"> </div>
<strong id="strong1">张三</strong>
<input id="text1" type="text" placeholder="请输入内容">
<input id="btn1" type="button" value="发送">
</body>
</html>