<div class="form">
<div class="con">
<ul>
<li>剩余字数的限制</li>
<li><textarea cols="40" rows="8" id="text1"></textarea></li>
<li>剩余字符:<span id="textleft"></span></li>
</ul>
</div>
</div>
<script language="javascript">
var otext = document.getElementById("text1");
var otextleft = document.getElementById("textleft");
var re = /[^x00-xff]/g;
var maxLength = 40;
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;
}
</script>
时间: 2024-10-01 17:57:34