日期:2014-05-16  浏览次数:20489 次

js计算剩余字符
<html>
<head>
<script type="text/javascript">
function checkLength(which) {
var maxChars = 250;
if (which.value.length > maxChars)
which.value = which.value.substring(0,maxChars);

var curr = maxChars - which.value.length;
document.getElementById("chLeft").innerHTML = curr.toString();
}
</script>
</head>
<body>
<textarea name="description" onkeyup="checkLength(this);"></textarea> <br />
<small>文字最大长度: 250. 还剩: <span id="chLeft">250</span>.</small>
</body>
</html>