<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{margin: 0;padding: 0px;}
.box1{width: 500px;height: 400px;background: pink;margin: 0 auto;}
.box2{width: 200px;height: 30px;font-size: 20px;line-height: 30px;float:right;}
.box2 span{font-size: 25px;}
textarea{width: 498px;height: 200px;background: #ccc;font-size: 20px;}
button{float:right;width: 40px;height: 20px;margin-right: 20px;background: blue;}
</style>
<script type="text/javascript">
var num, txt, x
window.onload = function (){
num = document.getElementById('num')
txt = document.getElementById('txt')
bt = document.getElementById('bt')
txt.onkeyup = function my(){
x = 140-txt.value.length
num.innerHTML = x
if(x>=0){
num.style.color ='red'
} else{
num.style.color= 'blue'
}
}
bt.onclick = function (){
if(x==140){
alert('请输入内容')
txt.foucus()
}else if(x<0){
alert('超出字数')
}else{alert('发布成功')
}
}
my()
}
</script>
</head>
<body>
<div class="box1">
<div class="box2">你还可以输入<span id="num"></span>个数字</div>
<textarea id="txt"></textarea>
<input type="button" value="发布" id="bt">
</div>
</body>
</html>