摘要:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>微博输入样式</title&
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>微博输入样式</title>
<style>
*{
font-size: 12px;
}
#main{
width: 600px;
height: 260px;
border: 8px solid pink;
margin: 0 auto;
}
#text2{
width: 540px;
height: 160px;
margin-left: 20px;
}
img{
width: 190px;
float: left;
}
#right{
float: left;
margin-left: 200px;
}
#main #bq,#tp,#sp,#ht,#cwb,#gk2{
float: left;
width: 40px;
height: 30px;
line-height: 32px;
padding-left: 20px;
margin-top: 20px;
}
#bq{
background: url("images/an5.png") no-repeat left center;
}
#tp{
background: url("images/an4.png") no-repeat left center;
}
#sp{
background: url("images/an3.png") no-repeat left center;
}
#ht{
background: url("images/an2.png") no-repeat left center;
}
#cwb{
background: url("images/an1.png") no-repeat left center;
}
#gk2{
margin-left: 100px;
}
#bt{
margin-top: 20px;
}
</style>
</head>
<body>
<script>
var text,number,m;
window.onload = function(){
text = document.getElementById('text2');
number = document.getElementById('number');
bt = document.getElementById('bt');
text.onkeyup= function aa() {
m = 140-text.value.length;
if(m<0){
number.style.color="red";
}else {
number.style.color="#888";
}
number.innerHTML=m;
};
bt.onclick=function(){
if (m == 140) {
alert("你还没有输入");
text.focus()
}else if(m<0){
alert("字数太多,不可以发布");
text.focus()
}else{
alert("发布成功");
}
};
aa();
}
</script>
<div id="main">
<img src="images/12.png" alt="">
<div id="right">
你还可以输入<span id="number"></span>字
</div>
<textarea id="text2" >1</textarea>
<span id="bq">表情</span>
<span id="tp">图片</span>
<span id="sp">视频</span>
<span id="ht">话题</span>
<span id="cwb">长微博</span>
<span id="gk2">公开</span>
<input type="button" value="发布" id="bt">
</div>
</body>
</html>
批改老师:灭绝师太批改时间:2018-11-12 09:08:04
老师总结:基本上跟老师代码一样啊,这样可不行……语句中有个错误,aa()只是老师测试用的,你们不要添加aa(),匿名函数自调用……