abstract:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml&quo
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>weibo输入</title>
<style type="text/css">
body{ font-size:12px;}
.box{
margin: auto;
height: 160px;
width: 600px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #FF80FF;
border-right-color: #FF80FF;
border-bottom-color: #FF80FF;
border-left-color: #FF80FF;
padding: 10px;
}
img{
float: left;
}
.box1{
float: left;
height: 24px;
width: 150px;
margin-left: 255px;
text-align: right;
font-size: 9px;
color: #888;
}
.box1 span{
font-size: 16px;
font-weight: bold;
}
#text{
height: 100px;
width: 600px;
margin-top: 5px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
}
.box #sp1,#sp2,#sp1,#sp3,#sp4,#sp5,#sp6{
float: left;
height: 32px;
width: 30px;
padding-left: 26px;
line-height: 32px;
}
#sp1{
background-image: url(images/an5.png);
background-repeat: no-repeat;
background-position: left center;
}
#sp2{
background-image: url(images/an4.png);
background-repeat: no-repeat;
background-position: left center;
}
#sp3{
background-image: url(images/an3.png);
background-repeat: no-repeat;
background-position: left center;
}
#sp4{
background-image: url(images/an2.png);
background-repeat: no-repeat;
background-position: left center;
}
#sp5{
background-image: url(images/an1.png);
background-repeat: no-repeat;
background-position: left center;
width: 40px;
}
#sp6{
margin-right: 15px;
margin-left: 150px;
color: #888;
}
#bt{
float: left;
height: 30px;
width: 80px;
background-color: #ffc09f;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
border-top-color: #fff;
border-right-color: #fff;
border-bottom-color: #fff;
border-left-color: #fff;
border-radius: 5px;
margin-top: 2px;
}
</style>
<script>
var text,number,m
window.onload=function(){
text=document.getElementById("text")
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>
</head>
<body>
<div class="box">
<img src="images/12.png">
<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">
</body>
</html>
<!--CSS总结
border-radius: 圆角
JS总结
getElementById() 返回带有指定ID的元素
innerHTML 写入到HTML元素
windown.onload 浏览器已完成页面的加载
if...else if...else 用来选择代码块之一来执行
-->
Correcting teacher:天蓬老师Correction time:2018-12-30 13:31:42
Teacher's summary:如果觉得getElementById() 等这些方法太麻烦,不妨用: querySelector()等,再方便