abstract:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> *{margin: 0;padding: 
<!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('請(qǐng)輸入內(nèi)容') txt.foucus() }else if(x<0){ alert('超出字?jǐn)?shù)') }else{alert('發(fā)布成功') } } my() } </script> </head> <body> <div class="box1"> <div class="box2">你還可以輸入<span id="num"></span>個(gè)數(shù)字</div> <textarea id="txt"></textarea> <input type="button" value="發(fā)布" id="bt"> </div> </body> </html>
Correcting teacher:天蓬老師Correction time:2019-02-20 09:14:10
Teacher's summary:以后的js代碼, 還是把分號(hào)加上吧, 現(xiàn)在官方,又開始推薦把分號(hào)加上了, 以防止代碼壓縮時(shí)出現(xiàn)解析錯(cuò)誤