< SCRIPT LANGUAGE = " JavaScript " > <!-- var maxLen = 100 ; function checkMaxInput(obj) ... { var m=obj.value.length; var n=m; var j=0; for (var i=0;i<m;i++) ...{ if (obj.value.charCodeAt(i)<0||obj.value.charCodeAt(i)>161) ...{ n=n+1; if ( i < 100 ) ...{ j=j+1; } } } if(n>maxLen) ...{ obj.value=obj.value.substring(0,maxLen-j); remLen1.innerText='[最大可输入'; remLen2.innerText=maxLen; remLen3.innerText='字符,'; remLen4.innerText='您已达到输入上限!'; remLen5.innerText=']'; } else ...{ remLen1.innerText='[最大可输入'; remLen2.innerText=maxLen; remLen3.innerText='字符,还可输入'; remLen4.innerText=maxLen-n; remLen5.innerText='字符]'; } } // --> </ SCRIPT > < textarea name = " creditcontent " cols = " 45 " rows = " 5 " onKeyDown = " checkMaxInput(this) " onKeyUp = " checkMaxInput(this) " onBlur = " checkMaxInput(this) " class = " 12pxbd " ></ textarea > < br > < font id = " remLen1 " ></ font > < font color = red id = " remLen2 " ></ font > < font id = " remLen3 " ></ font > < font color = red id = " remLen4 " ></ font > < font id = " remLen5 " ></ font > 很有用的JS,先收藏在这里