当前位置: 代码迷 >> JavaScript >> JS 提醒输入字符数
  详细解决方案

JS 提醒输入字符数

热度:44   发布时间:2012-11-08 08:48:11.0
JS 提示输入字符数
<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>

 <table>
   	<tr>
   		<td>
   			<textarea name="description" onkeyup="checkLength(this);"></textarea>
			<br />
			<small><font color="red">文字最大长度: 100. 还剩:</font><font color="blue"> <span id="chLeft">100</span>.</font></small>
   		</td>
   	</tr>
   </table>
  相关解决方案