我正在尝试创建一个动态文本区域,但我不知道如何修复 keyup 操作,因此调整大小功能仅在 /n 存在时才起作用
脚本:
function ResizeTextArea() {
var msgTxtHeight = $("#<%=Message_txt.ClientID %>").css("height");
var containerDivHeight = $(".MsgDiv").css("max-height");
if ($("#<%=Message_txt.ClientID %>").val() == "") {
$("#<%=ConversationDIv.ClientID %>").css("height", "318px");
$("#<%=Message_txt.ClientID %>").css("height","15px");
}
if (msgTxtHeight >= containerDivHeight) { return false; }
$("#<%=Message_txt.ClientID %>").css("height", $("#<%=Message_txt.ClientID %>").height() + 15);
$("#<%=ConversationDIv.ClientID %>").height($("#<%=ConversationDIv.ClientID %>").height() - 15);
}
html:
<div id="ConversationDIv" runat="server" clientidmode="Static" style="height: 318px;
width: 100%; overflow: auto;" class='convoDiv'>
</div>
<table border="0" width="100%">
<tr>
<td align="left" style="width: 91%">
<div class="MsgDiv">
<asp:TextBox ID="Message_txt" runat="server" Width="100%" TextMode="MultiLine" CssClass="Messagetxt" onkeyup="ResizeTextArea();"></asp:TextBox>
</div>
</td>
</tr></table>
jsfiddle:http: //jsfiddle.net/49HQM/195/