有时候需要在JS控制TEXTAREA框里字符的个数,下面我们一起看看实现方法。
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" />
<meta name=\"robots\" content=\"all\" />
<meta name=\"author\" content=\"bigfocus@163.com,混蛋鱼\" />
<meta name=\"Copyright\" content=\"混蛋鱼VS男人猫 CopyRight 2007\" />
<meta name=\"keywords\" content=\"JS,Blog,asp,designing,with,web,standards,xhtml,css,graphic,design,layout,usability,accessibility,w3c,w3,w3cn\" />
<meta name=\"descrīption\" content=\"JS限制textarea输入框输入字数\" />
<title>JS限制textarea输入框输入字数</title>
<scrīpt language=\"javascrīpt\">
<!--
function checktext(text)
{
allValid = true;
for (i = 0; i < text.length; i++)
{
if (text.charAt(i) != \" \")
{
allValid = false;
break;
}
}
return allValid;
}
function gbcount(message,total,used,remain)
{
var max;
max = total.value;
if (message.value.length > max) {
message.value = message.value.substring(0,max);
used.value = max;
remain.value = 0;
alert(\"留言不能超过 200 个字!\");
}
else {
used.value = message.value.length;
remain.value = max - used.value;
}
}