<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
.body{font-size: 12px;}
.box{width: 600px; height:200px;border:8px solid pink;margin: 0px auto;position: relative;margin-top: 400px;}
.box1{margin-left:450px;float: left;width: 130px;height: 24px;text-align: right;}
#text{width: 500px;height: 120px;margin-top: 15px;margin-left: 50px;}
.box #sp1,#sp2,#sp3,#sp4,#sp5,#sp6{float:left;width: 30px;line-height: 30px;font-size: 12px;font-weight: bold;margin-left: 50px;}
#sp6{margin-right: 25px;}
#bt{float: left;border: none ;background: # #999999;width: 80px;height: 30px;border-radius: 5px;}
</style>
<script>
var text,number,m
window.onload=function(){
text=document.getElementById('text')
number=document.getElementById('number')
bt=document.getElementById('bt')
//当enter 按键按起来的时候执行代码
text.onkeyup = function aa(){
m=140-(text.value.length)//微博限制字数
if(m<0){
number.style.color = 'red';
}else{
number.style.color = '#FF7F50';
}
number.innerHTML = m
}
//当鼠标点击按钮时候触发的事件
bt.onclick = function(){
if(m==140){
alert('您还没有输入')
text.focus()
}else if(m<0){
alert('字数过多')
text.focus()
}else{
alert("发布成功")
}
}
aa()
}
</script>
</head>
<body>
<div class="box">
<div class="box1">
还可以输入<span id="number"></span>字
</div>
<textarea id="text"></textarea>
<span id="sp1">话题</span>
<span id="sp2">热搜</span>
<span id="sp3">微博</span>
<span id="sp4">观点</span>
<span id="sp5">讨论</span>
<span id="sp6">公告</span>
<input type="button" value="发布" id="bt" />
</div>
</body>
</html>