使用MultiLine TextBox(生成TextArea)设置时,MaxLength属性无效.什么是最好的解决方法?我希望得到基本的,预期的功能,最少的丑陋javascript等.只是防止用户输入超过最大字符数.
Axi*_*ili 24
如果您不关心旧浏览器(请参阅此处支持的浏览器),
您可以像这样设置MaxLength
<asp:TextBox ID="txt1" runat="server" TextMode="MultiLine" MaxLength="100" />
Run Code Online (Sandbox Code Playgroud)
并强制它打印到HTML
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
txt1.Attributes.Add("maxlength", txt1.MaxLength.ToString());
}
Run Code Online (Sandbox Code Playgroud)
嘿pukipuki你可以做如下:
<asp:TextBox ID="txtValue" runat="server"TextMode="MultiLine" Rows="10"Columns="50"></asp:TextBox>
$(document).ready(function(){
var MaxLength = 250;
$('#txtValue').keypress(function(e)
{
if ($(this).val().length >= MaxLength)
{
e.preventDefault();
}
});});
Run Code Online (Sandbox Code Playgroud)
您可以在以下链接中查看更多内容:http: //jquerybyexample.blogspot.in/2010/10/set-max-length-for-aspnet-multiline.html