<script language=javascript> var otext = document.getElementById("text1"); var otextleft = document.getElementById("textleft"); var re = /[^/x00-/xff]/g; var maxLength = 20; window.onload = function(){ if(document.all) otext.onpropertychange = textleft; else otext.onkeypress = textleft; } function textleft() { var str = otext.value; str = str.replace(re,"xx");//中文字符当2个字符处理 如果不用的话主是掉本行 otextleft.innerHTML = maxLength - str.length; if((maxLength - str.length)<0){ otext.value=otext.value.substr(0,otext.value.length-1); } } </script>
限制多行文本框的输入长度并显示剩余字符
最新推荐文章于 2023-07-19 14:21:48 发布