当前位置: 代码迷 >> JavaScript >> js计算余下字符
  详细解决方案

js计算余下字符

热度:28   发布时间:2012-10-30 16:13:36.0
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>
  相关解决方案