惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
V
Visual Studio Blog
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
B
Blog
I
InfoQ
博客园 - 三生石上(FineUI控件)
阮一峰的网络日志
阮一峰的网络日志
F
Fortinet All Blogs
H
Help Net Security
博客园 - Franky
宝玉的分享
宝玉的分享
博客园 - 司徒正美
C
Check Point Blog
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Jina AI
Jina AI
T
The Blog of Author Tim Ferriss
MongoDB | Blog
MongoDB | Blog
云风的 BLOG
云风的 BLOG
A
About on SuperTechFans
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家

博客园 - 天若有情

解密不同编码的参数 - 天若有情 - 博客园 出现“创建挂起的文件操作”解决办法 asp使用绑定变量方法 利用C#来重启另一个程序 - 天若有情 - 博客园 实用Javascript代码段 - 天若有情 - 博客园 防止图片把网页撑大的代码 增加和删除Html节点方法: - 天若有情 - 博客园 .net Framework 2.0 发送邮件 转载:网站策划方案写作、演示标准 检测是否还有黑客代码的asp.net函数 - 天若有情 - 博客园 显示指定的错误页面,同时把错误信息写入系统日志文件 - 天若有情 - 博客园 关于错误处理的自定义错误页面 - 天若有情 - 博客园 C#页面统一错误处理 - 天若有情 - 博客园 一个处理数据库异常的类,按照错误码弹出提示信息 一个正则表达式的类 ASP.NET程序中常用代码汇总(二) ASP.NET程序中常用代码汇总(一) 自建工具集开发文档------异常处理(1.0.0.1) asp.net URL重写续
多行文本框限制输入字符长度(两种方法)
天若有情 · 2006-09-14 · via 博客园 - 天若有情

方法一:弹出对话框提示
1.html代码

<HTML>
    
<HEAD>
        
<title>WebForm6</title>
        
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        
<meta name="CODE_LANGUAGE" Content="C#">
        
<meta name="vs_defaultClientScript" content="JavaScript">
        
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
        
<script language="javascript">            
            
function isOver(sText,len)
            
{
                
var intlen=sText.value.length;
                
if (intlen>len)
                
{
                    alert(
"The content length must Less than or Equal "+len);
                    sText.focus();
                    sText.select();
                }

            }

        
</script>
    
</HEAD>
    
<body MS_POSITIONING="GridLayout">
        
<form id="Form1" method="post" runat="server">
            
<asp:TextBox id="txtName" style="Z-INDEX: 102; LEFT: 200px; POSITION: absolute; TOP: 104px" runat="server"
                TextMode
="MultiLine" Height="112px" Width="271px"></asp:TextBox>
        
</form>
    
</body>
</HTML>

2.cs代码

private void Page_Load(object sender, System.EventArgs e)
        
{
            
this.txtName.Attributes.Add("onblur","isOver(this,1000);");
        }

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

<HEAD>
    
<!-- TWO STEPS TO INSTALL LIMIT TEXTAREA:

  1.  Copy the coding into the HEAD of your HTML document
  2.  Add the last code into the BODY of your HTML document  
-->
    
<!-- STEP ONE: Paste this code into the HEAD of your HTML document  -->
    
<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Ronnie T. Moore -->
<!-- Web Site:  The JavaScript Source -->

<!-- Dynamic 'fix' by: Nannette Thacker -->
<!-- Web Site: http://www.shiningstar.net -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too longtrim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value 
= maxlimit - field.value.length;
}

// End -->
    
</SCRIPT>
    
<!-- STEP TWO: Copy this code into the BODY of your HTML document  -->
</HEAD>
<BODY>
    
<!-- textCounter() parameters are:  text field, the count field, max length -->
    
<center>
        
<form name="myform" action="YOUR-SCRIPT.CGI">
            
<font size="1" face="arial, helvetica, sans-serif">( You may enter up to 125 
                characters. )
<br>
                
<textarea name="message" wrap="physical" cols="28" rows="4" onKeyDown="textCounter(this.form.message,this.form.remLen,125);"
                    onKeyUp
="textCounter(this.form.message,this.form.remLen,125);"></textarea>
                
<br>
                
<input readonly type="text" name="remLen" size="3" maxlength="3" value="125"> characters 
                left
</font>
        
</form>
    
</center>
    
<p><center>
            
<font face="arial, helvetica" SIZE="-2">Free JavaScripts provided<br>
                by 
<href="http://javascriptsource.com">The JavaScript Source</a></font>
        
</center>
</BODY>