中文(简体)
<!-- http://www.downcodes.com/js --> <!-- bbs http://www.downcodes.com/bbs--> <!-- 完整的 HTML 代码 --> <html > <head> <style type="text/css"> .progress{ 宽度:1px;高度:14px;颜色: 白色;字体大小:12px;溢出:隐藏;背景颜色:海军蓝;左内边距:5px; } </style> <script type="text/JavaScript"> function textCounter(field,counter,maxlimit,linecounter) { // 文本宽度// var fieldWidth = parseInt(field.offsetWidth); var charcnt = 字段.值.长度; // 修剪多余的文本 if (charcnt > maxlimit) { field.value = field.value.substring(0, maxlimit); } else { // 进度条百分比 var Percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ; document.getElementById(counter).style.width = parseInt((fieldWidth*percentage)/100)+"px"; document.getElementById(counter).innerHTML="Limit: "+percentage+"%" // 对来自 CCFFF -> CC0000 的样式进行颜色校正 setcolor(document.getElementById(counter),percentage,"background-color"); } } function setcolor(obj,percentage,prop){ obj.style[prop] = "rgb(80%,"+(100-百分比)+"%,"+(100-百分比)+"%)"; } </script> </head> <body> <form> <textarea rows="5" cols="40" name="maxcharfield" id="maxcharfield" onKeyDown="textCounter(this,'progressbar1',20) " onKeyUp="textCounter(this,'progressbar1',20)" onFocus="textCounter(this,'progressbar1',20)" ></textarea><br /> <div id="progressbar1" class="progress" ></div> <script>textCounter(document.getElementById("maxcharfield"),"progressbar1",20)</script> </form> </body> </html> <br><br><br> <p><font color=red>//网站:http://www.downcodes.com</font></p>