我可以使用 javascript 或 C# 在多行 asp:TextBox 中限制为仅 3 个新行吗
only by setting Rows property to 3 you can achieve this like this:
<asp:TextBox ID="txtBox1" runat="server" Rows="3" TextMode="MultiLine"></asp:TextBox>
use 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)"/>
change the value of max_number
and maxchar_number
based on your requirement.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.