控制textarea 只能输入200个以内的字符。
<textarea cols="" rows=""></textarea>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <script language=javascript> <!-- var maxLen=200; 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> <body > <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> /body> </html>
?
转自http://lisily.blog.163.com/blog/static/2441452008101025454465/