<html>
<head>
<title>JS限制Textarea文本域字符個數</title>
<meta httpequiv="ContentType" content="text/html; charset=gb" />
<SCRIPT LANGUAGE="JavaScript">
<!//
function textCounter(field countfield maxlimit) {
// 函數個參數表單名字表單域元素名限制字符
if (fieldvaluelength > maxlimit)
//如果元素區字符數大於最大字符數按照最大字符數截斷
fieldfieldvalue = fieldvaluesubstring( maxlimit);
else
//在記數區文本框內顯示剩余的字符數
countfieldvalue = maxlimit fieldvaluelength;
}
>
</SCRIPT>
</head>
<body>
<form name=myform action="">
<textarea name="message" cols="" rows="" onKeyDown="textCounter(messageremLen);" onKeyUp=
"textCounter(messageremLen);"></textarea>
您還可以輸入:<input name="remLen" type="text" value="" size="" readonly="readonly">個字符
</form>
</body>
</html>
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20028.html