<!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="keywords" content="" />
<meta name="description" content="" />
<title></title>
</head>
<body>
<script language="javascript">
function countChar(textareaName,spanName){
if(document.getElementById("status").value.length>100){
window.alert("已经是最大字数了!")
return false;
}else{
document.getElementById("counter").innerHTML=document.getElementById(textareaName).value.length;
}
}
</script>
<textarea id="status" name="status" cols="50" rows="10" οnkeydοwn='countChar("status","counter");' οnkeyup="countChar('status','counter');" ></textarea>
可以输入<span id="counter">0</span>/100字
</body>
</html>
转载于:https://blog.51cto.com/maobin/1359135