最新JS限制文本框输入指定字数示例
以下是三零网为大家整理的最新JS限制文本框输入指定字数示例的文章,希望大家能够喜欢!
javascript:
<script language="javascript"><!-- function checkLength(which) { var maxChars = 20; 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> |
HTML:
<div> <asp:TextBox ID="txtInput" runat="server" Width="200px" Height="60px" onkeyup="checkLength(this);" TextMode="MultiLine"></asp:TextBox> <br /> <small>文字最大长度: 20. 还剩: <span id="chLeft">20</span>.</small> </div> |
联系客服