限制文本框输入字数

效果自己测试了。

<html>
<head>
<title>网页特效-表单特效-限制文本框输入字数</title>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
</head>
<body>
<!–把下面代码加到<body>与</body>之间–>
<script language="JavaScript">
<!– Begin
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0,maxlimit);
else
countfield.value = maxlimit – field.value.length;
}
// End –>
</script>
<form name="form" action="" method="post">
  <textarea class="editbox2" onKeyDown="textCounter(this.form.memo,this.form.remLen,160)" onKeyUp="textCounter(this.form.memo,this.form.remLen,160)" name="memo" cols="45" rows="8" wrap="on"></textarea>
  <br>
  共可输入160字,还剩
  <input class="editbox1" readOnly maxLength="3" size="3" value="160" name="remLen">
  字。<br>
  <input class="bottom" type="submit" value=" 提交 " name="submit">
  <input class="bottom" type="reset" value=" 重置 " name="reset">
</form>
</body>
</html>