<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>
javascript TextArea动态显示剩余字符
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@