摘要:<!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">發(fā)布</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("你還沒有輸入內(nèi)容"); text.focus(); }else if(m<0){ alert("你的內(nèi)容輸入過多,不能發(fā)布"); text.focus(); }else{ alert("發(fā)布成功"); } } aa(); } </script> </body> </html>
總結(jié):本節(jié)課學(xué)習(xí)的是JS案例--微博輸入字?jǐn)?shù),前面的布局是自己敲出來的,后面的JS代碼是根據(jù)老師的步驟敲出來的,現(xiàn)在自己還不能完全脫離老師的代碼敲出來,還是要多加練習(xí)。
批改老師:西門大官人批改時間:2019-04-02 10:36:01
老師總結(jié):孰能生巧,多寫代碼,思路就清晰了。繼續(xù)加油