以前写过检测文本框中字数的方法,效果不好,原因在于:onKeyDown="showLen(this)" onKeyUp="showLen(this)
以前每次只用了其中一个方法,而且没有者用,这二个方法是在你按下键盘与松开键盘时都进行计数。
例子:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title> new document </title>
<meta name="generator" content="editplus">
<meta name="author" content="">
<meta name="keywords" content="">
<meta name="description" content="">
<mce:script language="javascript"><!--
function showlen(obj)
{
document.getelementbyid("contentlen").value=obj.value.length;
document.getelementbyid("smsnum").value=math.floor(obj.value.length/70)+1;
}
// --></mce:script>
</head>
<body>
<textarea name="content" cols="60" rows="5" id="content" onkeydown="showlen(this)" onkeyup="showlen(this)">