多行文本框限制输入字符长度(两种方法)
来源:互联网 发布:淘宝店哪些东西利润高 编辑:程序博客网 时间:2024/04/30 14:07
方法一:弹出对话框提示
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代码<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>
private void Page_Load(object sender, System.EventArgs e)
{
this.txtName.Attributes.Add("onblur","isOver(this,1000);");
}
方法二:限制用户继续输入{
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 <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center>
</BODY>
<!-- 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 <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center>
</BODY>
- 多行文本框限制输入字符长度(两种方法)
- 多行文本框限制输入字符长度(两种方法)
- 多行文本框限制输入字符长度(两种方法)
- 多行文本框限制输入字符长度(两种方法)
- 限制多行文本框的输入长度并显示剩余字符
- 关于多行文本框限制输入长度(收藏)
- asp.net 多行文本框输入长度限制
- 多行文本框限制输入字符数TextBox
- 利用JS限制多行文本框字符输入个数
- Javascript限制多行文本输入框的字符数
- Javascript限制多行文本输入框的字符数
- 多行文本框长度限制
- 多行文本框限制文本长度
- 多行文本框如何限制输入字数方法
- 限制多行文本框textarea输入字数的方法
- 限制多行文本输入字符限制和显示
- 验证多行文本框输入长度的正则表达式
- 多行文本框的字符数限制
- Hibernate入门20 - cascade持久化
- 简单验证码的产生
- 双向关联与inverse设定
- 帮看网:web2.0的网页监控服务
- Google公布06年十大搜索词 “视频/video”居首
- 多行文本框限制输入字符长度(两种方法)
- 浅显的谈谈证券公司的信息化
- 取得控件绝对位置
- Windows Vista:通信基础结构
- TextBox上实现右键菜单
- Java开发者必去的技术网站
- 汉诺塔问题
- 学术诚信:人生守则的试金石
- 实用的Web进度条