关于多行文本框限制输入长度(收藏)

方法一:
 
  1. <HTML>
  2.     <HEAD>
  3.         <title>WebForm6</title>
  4.         <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
  5.         <meta name="CODE_LANGUAGE" Content="C#">
  6.         <meta name="vs_defaultClientScript" content="JavaScript">
  7.         <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
  8.         <script language="javascript">            
  9.             function isOver(sText,len)
  10.             {
  11.                 var intlen=sText.value.length;
  12.                 if (intlen>len)
  13.                 {
  14.                     alert("The content length must Less than or Equal "+len);
  15.                     sText.focus();
  16.                     sText.select();
  17.                 }
  18.             }
  19.         </script>
  20.     </HEAD>
  21.     <body MS_POSITIONING="GridLayout">
  22.         <form id="Form1" method="post" runat="server">
  23.             <asp:TextBox id="txtName" style="Z-INDEX: 102; LEFT: 200px; POSITION: absolute; TOP: 104px" runat="server"
  24.                 TextMode="MultiLine" Height="112px" Width="271px"></asp:TextBox>
  25.         </form>
  26.     </body>
  27. </HTML>
  28. private void Page_Load(object sender, System.EventArgs e)
  29.         {
  30.             this.txtName.Attributes.Add("onblur","isOver(this,1000);");
  31.         }

方法二:限制用户继续输入

  1. <HEAD>
  2.     <!-- TWO STEPS TO INSTALL LIMIT TEXTAREA:
  3.   1.  Copy the coding into the HEAD of your HTML document
  4.   2.  Add the last code into the BODY of your HTML document  -->
  5.     <!-- STEP ONE: Paste this code into the HEAD of your HTML document  -->
  6.     <SCRIPT LANGUAGE="JavaScript">
  7. <!-- Original:  Ronnie T. Moore -->
  8. <!-- Web Site:  The JavaScript Source -->
  9. <!-- Dynamic 'fix' by: Nannette Thacker -->
  10. <!-- Web Site: http://www.shiningstar.net -->
  11. <!-- This script and many more are available free online at -->
  12. <!-- The JavaScript Source!! http://javascript.internet.com -->
  13. <!-- Begin
  14. function textCounter(field, countfield, maxlimit) {
  15. if (field.value.length > maxlimit) // if too longtrim it!
  16. field.value = field.value.substring(0, maxlimit);
  17. // otherwise, update 'characters left' counter
  18. else 
  19. countfield.value = maxlimit - field.value.length;
  20. }
  21. // End -->
  22.     </SCRIPT>
  23.     <!-- STEP TWO: Copy this code into the BODY of your HTML document  -->
  24. </HEAD>
  25. <BODY>
  26.     <!-- textCounter() parameters are:  text field, the count field, max length -->
  27.     <center>
  28.         <form name="myform" action="YOUR-SCRIPT.CGI">
  29.             <font size="1" face="arial, helvetica, sans-serif">( You may enter up to 125 
  30.                 characters. )<br>
  31.                 <textarea name="message" wrap="physical" cols="28" rows="4" onKeyDown="textCounter(this.form.message,this.form.remLen,125);"
  32.                     onKeyUp="textCounter(this.form.message,this.form.remLen,125);"></textarea>
  33.                 <br>
  34.                 <input readonly type="text" name="remLen" size="3" maxlength="3" value="125"> characters 
  35.                 left</font>
  36.         </form>
  37.     </center>
  38.     <p><center>
  39.             <font face="arial, helvetica" SIZE="-2">Free JavaScripts provided<br>
  40.                 by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
  41.         </center>
  42. </BODY>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值