摘要:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>微博输入</title> <style> *{margin:0;padding:0;} &nbs
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>微博输入</title>
<style>
*{margin:0;padding:0;}
.box{
width:650px;
height:180px;
border:10px solid blue;
margin:10px auto;
padding:10px;
}
img{
float:left;
}
.box2{
width:150px;
height:24px;
float:right;
line-height:24px;
text-align:right;
font-size:14px;
}
.clear{
clear:both;
}
#text{
width:650px;
height:115px;
border:1px solid #000;
margin:10px 0 5px;
}
ul li{
list-style:none;
float:left;
margin-left:10px;
}
span{
font-size:10px;
}
p{
float:right;
font-size:14px;
margin-right:20px;
line-height:24px;
}
button{
border:none;
border-radius:5px;
width:70px;
background:#FFC09F;
text-align:center;
color:#fff;
line-height:28px;
float:right;
margin-top:-3px;
}
.box2 span{
font-size:20px;
font-weight:800;
}
</style>
</head>
<body>
<div class="box">
<img src="images/12.png" alt="">
<div class="box2">还可以输入<span id="number"></span>字</div>
<div class="clear"></div>
<textarea id="text"></textarea>
<ul>
<li>
<img src="images/an5.png" alt=""><span>表情</span>
</li>
<li>
<img src="images/an4.png" alt=""><span>图片</span>
</li>
<li>
<img src="images/an3.png" alt=""><span>视频</span>
</li>
<li>
<img src="images/an2.png" alt=""><span>话题</span>
</li>
<li>
<img src="images/an1.png" alt=""><span>长微博</span>
</li>
</ul>
<button id="bt">发布</button>
<p>公开</p>
</div>
<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>
</body>
</html>总结:本节课学习的是JS案例--微博输入字数,前面的布局是自己敲出来的,后面的JS代码是根据老师的步骤敲出来的,现在自己还不能完全脱离老师的代码敲出来,还是要多加练习。
批改老师:西门大官人批改时间:2019-04-02 10:36:01
老师总结:孰能生巧,多写代码,思路就清晰了。继续加油