<SCRIPT language=JavaScript>
function length(){
messageCount.innerText = document.addform.request.value.length;//如果文本框中有字符加载页面就计算其个数
}
</SCRIPT>
<SCRIPT language=JavaScript>
function textLimitCheck(thisArea, maxLength){//根据onkeyup事件计算文本框中的字符个数,限制在500以内
if (thisArea.value.length > maxLength){
alert(maxLength + ' 个字限制. \r超出的将自动去除.');
thisArea.value = thisArea.value.substring(0, maxLength);
thisArea.focus();
}
/*回写span的值,当前填写文字的数量*/
messageCount.innerText = thisArea.value.length;
}
</SCRIPT>
<body onLoad="length()">
<span style="LINE-HEIGHT: 180%">
<textarea name="request" cols="45" rows="8" onKeyUp="textLimitCheck(this, 500);">//调用的事件
</textarea>
<BR>
限500 个字符已输入<FONT color=#cc0000><SPAN id=messageCount>0</SPAN></FONT> 个字</span>
</body>