.Aspx源 <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"> <mce: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(); } } // --></mce: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> .cs代码 private void Page_Load(object sender, System.EventArgs e) { this.txtName.Attributes.Add("onblur","isOver(this,1000);"); } 注:onblur 事件会在对象失去焦点时发生,这里增加的属性名称是不可以用其它名称的