动态统计输入字符的个数!

<html>
<head>
<title>动态统计输入字符的个数!</title>
<script language="javascript">
//统计字符数量
function countChars()
{
   var s = document.getElementById("description").value;
   if(!isMaxString(s,100))
   {
      document.getElementById("description").value = s.substring(0,100);
   }
   document.getElementById("count").value = document.getElementById("description").value.length+1;
}
//检测字符的数量
function isMaxString(inputString,count)
{
   if(inputString.length>count)
      return false;
   else
      return true;
}
</script>
</head>
<body>
<table>
<tr>
  <td width="250">请输入文字说明:</td>
  <td><input type="text" id="count" align="right"></td>
</tr>
<tr>
   <td colspan="2"><textarea id="description" style="width:300px;height:100px" onKeyDown="countChars();"></textarea></td>
</tr> 
</table>
</body>
</html>
posted on 2007-08-05 14:28  Bēniaǒ  阅读(397)  评论(0编辑  收藏  举报