本文介绍了修复asp.net中文本框的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<asp:TextBox ID=txtComments runat="server" BorderColor="Gray"
BorderStyle="Solid" BorderWidth="1px" CausesValidation="true" Wrap="true"
MaxLength="100"
TextMode="MultiLine"
Width="350px">
在aspx.cs文件中
in aspx.cs file
public int MaxLength
{
get { return txtComments.MaxLength; }
set { txtComments.MaxLength = value; }
}
public void wordCount()
{
txtCount.Text = txtComments.MaxLength.ToString();
txtComments.Attributes.Add("onKeyUp", "javascript:document.getElementById(''" + txtCount.ClientID + "'').setAttribute(''value'', (" + txtComments.MaxLength + " - parseInt(document.getElementById(''" + txtComments.ClientID + "'').getAttribute(''value'').length)));");
}
我正在我的应用程序中编写以下代码..c有人能告诉我如何将光标固定在文本框中最后一个字符的末尾吗??
预先谢谢你.
[edit]添加了代码块-OriginalGriff [/edit]
i was writing following code in my application.. ccan anyone tell me that how can i fixed the cursor at the end of last character in textbox...?
thank you in advance.
[edit]Code blocks added - OriginalGriff[/edit]
推荐答案
focus()
onKeyUp() //(after all other code)
onMouseUp()
并将光标设置到末尾只需执行以下操作:this.value = this.value;
在javascript事件中,因为这会将(框内的)文本设置为自身,从而迫使光标重置到末尾.
and to set the cursor to the end simply do:this.value = this.value;
in the javascript event as this will set the text (of the box) to itself thus forcing the cursor to be reset to the end.
这篇关于修复asp.net中文本框的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!