<div class="htmlarea"><textarea id="runcode20505"> <div id="msg"></div> <textarea maxlength="10" id="txt"> <script> function checkLen() {var obj=inputTxt var maxLen=parseInt(obj.getAttribute('maxlength')) //最大限制输入的字符数量 var len=obj.value.replace(/[^\x00-\xff]/g,'oo').length; var llen=maxLen-len; if(len>maxLen) { var i=0; for(var z=0;z<len;z++) { if(obj.value.charCodeAt(z)>255) { i=i+2; }else { i=i+1; } if(i>=maxLen) { obj.value=obj.value.slice(0,(z + 1)); break; } } } if(llen<0)llen=0 if(len<maxLen)len=maxLen document.getElementById('msg').innerHTML='已输入字符数量:'+len+' 剩余数量:'+llen } var inputTxt=document.getElementById('txt'); if(!/msie/i.test(navigator.userAgent)) inputTxt.addEventListener("input",checkLen,false); else {inputTxt.onpropertychange=checkLen} </script> </textarea><br><input onclick="runEx('runcode20505')" type="button" value="运行代码"> <input onclick="doCopy('runcode20505')" type="button" value="复制代码"> <input onclick="doSave(runcode20505)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</textarea></div>