日期:2014-05-19  浏览次数:20481 次

关于TextBox限制每行输入的文本字数的问题,尽快解决的给80分,帮UP给20分
环境是2005中的   控件是服务器控件   是WEB页面,语言使用VB

我已经设置了TextMode属性为MultiLine,请问怎么能限制每行的最大输入长度为30

每行输入到30个字后自动换下一行,行数不要求限制。

也可以在javaScript中执行。


100分希望能得到详细的代码,谢谢了,马上下班了,明天来结贴

------解决方案--------------------
这恐怕有点麻烦...
------解决方案--------------------
每次输入的时候判断末尾距离上一个换行符之间的字符串长度,
似乎可以试一下.
------解决方案--------------------
http://community.csdn.net/Expert/topic/5338/5338052.xml?temp=.6429102
参考cpp2017(慕白兄)的:
<asp:TextBox ID= "TextBox1 " runat= "server "
style= "height:100%;overflow-y:hidden "
TextMode= "MultiLine "
onkeyup= "javacript:ResizeText(this); " Rows= "1 ">

</asp:TextBox>

<script>
function ResizeText(txt)
{
while(txt.scrollTop> 0)
{
txt.rows +=1;
}
}
</script>
------解决方案--------------------
友情帮顶
------解决方案--------------------
ding
------解决方案--------------------
顶!!
------解决方案--------------------
js:
<script language= "javascript ">
function CountText(source)
{
var currentValueLength;
var maxLength;
var objSource = document.getElementById(source);

if (null != objSource)
{
maxLength = objSource.limit;
currentValueLength = objSource.value.length;
var objCounter = document.all.LabelTextCounter;
if (null != objCounter)
{
var counterValue = maxLength - currentValueLength;
if (0 <= counterValue)
{
objCounter.innerHTML = counterValue ;
}
else
{
objCounter.innerHTML = 0;
objSource.value = objSource.value.substring(0, maxLength);
}
}
}
}
</script>

页面:
<asp:TextBox ID= "TextBox1 " runat= "server " Height= "80px " TextMode= "MultiLine " Width= "95% "> </asp:TextBox> 尚可输入 <label id= "LabelTextCounter "> 80 </label> 字符

Page_load里面:
tbx.Attributes[ "onKeyDown "] = "javascript:CountText( ' " + tbx.ClientID + " '); ";
tbx.Attributes[ "onKeyUp "] = "javascript:CountText( ' " + tbx.ClientID + " '); ";
tbx.Attributes[ "limit "] = "80 ";

------解决方案--------------------
这问题好象有点复杂,帮顶关注~
------解决方案--------------------
一句话
this.TextBox1.Attributes.Add( "onkeypress ", "return this.value.length!=5 ");
在注意拷贝与粘贴
this.TextBox1.Attributes.Add( "onpaste ", "return false ");