簡體   English   中英

我可以限制多行 asp:TextBox 中的新行數嗎

[英]Can I limit number of new lines in multiline asp:TextBox

我可以使用 javascript 或 C# 在多行 asp:TextBox 中限制為僅 3 個新行嗎

只有將 Rows 屬性設置為 3,您才能像這樣實現:

<asp:TextBox ID="txtBox1" runat="server" Rows="3" TextMode="MultiLine"></asp:TextBox>

使用javascript:

function validate(e, max,maxchar)
{
var text = e.value.replace(/\s+$/g,""); var split = text.split("\n");
if (split.length <= max && text.length <=maxchar)
{
  return true;
}
else if (split.length >= max || e.value.length >=maxchar)
{
 return false;
}
}
 <asp:TextBox ID="txtBox1" runat="server" TextMode="MultiLine" Rows="3" onkeypress="return validate(this,max_number,maxchar_number)"/>

根據您的要求更改max_numbermaxchar_number的值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM