<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{margin: 0;padding: 0;}
.container{
width: 280px;
margin: 20px auto;
border: 1px solid #ddd;
}
.container .content{
height: 400px;
padding: 10px;
overflow: auto;
}
.fl{
float: left;
}
.fr{
float: right;
}
.clear{
clear: both;
}
.footer{
border-top: 1px solid #ddd;
padding: 10px;
height:30px;
}
.footer img{
float: left;
}
.footer input{
float: left;
width: 140px;
outline: none;
border: 1px solid #ddd;
/*margin: 6px;*/
padding: 7px 8px;
margin-left: 10px;
margin-right: 5px;
}
.btn{
padding: 7px 8px;
outline: none;
border: none;
background: #8A2BE2;
color: #fff;
}
.active{
background: darkgreen;
color: #eee;
}
.text{
word-break: break-all;
max-width: 210px;
}
.msgL,.msgR{
margin-bottom: 15px;
}
</style>
</head>
<body>
<div class="container">
<div class="content" id="content">
</div>
<div class="footer">
<img src="img/QQ1.png" id="img" />
<input type="text" id="text"/>
<button class="btn" type="button" id="send">发送</button>
</div>
</div>
<script>
var oSend = document.getElementById("send")
var oText = document.getElementById("text")
var oContent = document.getElementById("content")
var oImg = document.getElementById("img")
var onOff = true
oSend.onclick = function(){
var oTxt = oText.value
if(oTxt.length==0){
alert('请输入内容')
}else{
if(onOff){
var str1 = '<div class="msgL fl clear"><div class="img_text"><div class="img fl"><img src="img/QQ1.png" /></div><div class="text fr">'+oTxt+'</div></div></div>'
oContent.innerHTML+=str1
oText.value = ""
}else{
var str2 = '<div class="msgR fr clear"><div class="img_text"><div class="img fr"><img src="img/QQ2.png" /></div><div class="text fl active">'+oTxt+'</div></div></div>'
oContent.innerHTML+=str2
oText.value = ""
}
}
}
oImg.onclick = function(){
if(onOff){
oImg.src = "img/QQ2.png"
onOff = false
}else{
oImg.src = "img/QQ1.png"
onOff = true
}
}
</script>
</body>
</html>
相关文章
- 01-09js五道经典练习题--第二道仿qq聊天框