<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>微博输入</title>
<style type="text/css">
*{margin:0;padding:0;}
.box{width:600px;height: 170px;border:10px solid pink; margin:0 auto;}
.box1{height: 24px;float: right; line-height:30px;text-align: center;font-size:14px;color: #888;}
.box1 span{font-size: 16px;font-weight: bold; line-height: 25px;}
textarea{width:100%;height: 100px; border:1px solid #888;margin-top:5px;}
#sp1,#sp2,#sp3,#sp4,#sp5,#sp6{}
#bt{ width:80px; height: 30px;border:none;background:#ffc09f;color: #fff }
</style>
<script>
window.onload=function(){
var text = document.getElementById('text');
var num = document.getElementById('num');
var bt = document.getElementById('bt');
text.onkeyup= function aa(){
var m=140-text.value.length;
if(m<0){
num.style.color='red';
}else{
num.style.color='#888';
}
num.innerHTML=m;
}
bt.onclick=function(){
if(m==140){
alert("您还没有输入");
text.focus();
}elseif(m<0){
alert('字数太多,不允许发布');
text.focus();
}
}
}
</script>
</head>
<body>
<div class="box">
<div class="box1">还可以输入<span id="num"></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 id="bt" type="button" name="" value="发布">
</div>
</body>
</html>