<head>
<script language="javascript">
function textLimitCheck(thisArea, maxLength)
{
if (thisArea.value.length > maxLength)
{
alert(maxLength + ’ 个字限制. \r超出的将自动去除’);
thisArea.value = thisArea.value.substring(0, maxLength);thisArea.focus();
}
messageCount.innerText = thisArea.value.length;/*回写span的值,当前填写文字的数量*/
}
</script>
</head>
调用方法:
<span style="color: #666666">限 500 个字符 已输入 </span><font color="#cc0000"><span id="messageCount"> 0</span></font><span style="color: #666666"> 个字</span>
<textarea id="tbtext" name="tbtext" onkeyup="textLimitCheck(this,500)" style="width:373px;height:77px;"></textarea>