javascript TextArea动态显示剩余字符
2010-09-14 13:30:22 来源:WEB开发网核心提示:<div class="form"><div class="con"><ul><li>剩余字数的限制</li><li><textarea cols="40" rows="8
<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>
Tags:javascript TextArea 动态
编辑录入:爽爽 [复制链接] [打 印]赞助商链接