多行文本框中的自动高度

时间:2011-08-04 13:10:32

标签: asp.net multiline

我必须使用多行文本框显示数据库中的数据 如何在此多行文本框中设置高度自动?
我的代码在这里,
<asp:TextBox ID="txtNaiyo" runat="server" TextMode="MultiLine" Rows="5" Width="100%" style="height:auto;" Value='<%# Eval("Naiyo") %>'/>

1 个答案:

答案 0 :(得分:3)

我做了一件非常容易的事情。首先,我将TextArea放入DIV中。其次,我已经为此脚本调用了Ready Function

<div id="divTable">
  <textarea ID="txt" Rows="1" TextMode="MultiLine" />
</div>

$(document).ready(function () {
  var heightTextArea = $('#txt').height();
  var divTable = document.getElementById('divTable');
  $('#txt').attr('rows', parseInt(parseInt(divTable .style.height) / parseInt(altoFila)));
});

简单。 div的Max Height一次是渲染,除以一行TextArea的高度。