[英]How to add number in each new line in a multiline textbox C# / ASP.net
[英]How to adjust number of rows for each asp.net multiline textbox in a table using jQuery?
我有一个具有多行的表。 这些行包含一个asp.net多行文本框
<table>
<tr>
<td>Invoice 1</td>
<td><asp:TextBox ID="invoiceDesc" runat="server" Rows="1" TextMode="MultiLine"></asp:TextBox></td>
</tr>
<tr>
<td>Invoice 2</td>
<td><asp:TextBox ID="invoiceDesc" runat="server" Rows="1" TextMode="MultiLine"></asp:TextBox></td>
</tr>
<tr>
<td>Invoice 3</td>
<td><asp:TextBox ID="invoiceDesc" runat="server" Rows="1" TextMode="MultiLine"></asp:TextBox></td>
</tr>
</table>
该表是使用asp.net gridview控件呈现的。 我试图根据加载的内容调整每个文本框的行数。
到目前为止,我已经尝试将下面的代码添加到$(document).ready中:
var text = $("#<%=invoiceDesc.ClientID%>").val();
var lines = text.split(/\r|\r\n|\n/);
var count = lines.length;
$('#<%=invoiceDesc.ClientID%>').attr('rows', count);
但是上面的jQuery代码不起作用。
替换下面给出的javascript代码,并通过您的textarea ID而不是我用作示例的测试。
var count = 20; //set the cols attribute of the textarea here i have set it to 20 just for an example which is by default for HTML textarea
var lineCount = ($('#test').val().length / count);
var lineBreaksCount = ($('#test').val().split('\r\n'));
alert(Math.round(lineCount)+1);
我希望这可以解决您的问题:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.