我使用Bootstrap来禁用TextArea的内容:
<td>
<textarea class="form-control disabled" id="message"></textarea>
</td>
它工作的很好,除了我需要控制高度以及基于被渲染到控件的内容。
是否有任何HTML 5技巧,或CSS技巧,我可以使用它来根据文本动态调整控件的高度?或者只能使用JScript实现这一点?
发布于 2014-08-27 10:32:17
试试这个:
演示
HTML:
<textarea id="ta" class="form-control disabled" id="message"></textarea>
CSS:
textarea {
resize:none;
}
剧本:
$("#ta").keyup(function (e) {
autoheight(this);
});
function autoheight(a) {
if (!$(a).prop('scrollTop')) {
do {
var b = $(a).prop('scrollHeight');
var h = $(a).height();
$(a).height(h - 5);
}
while (b && (b != $(a).prop('scrollHeight')));
};
$(a).height($(a).prop('scrollHeight') + 20);
}
autoheight($("#ta"));
发布于 2014-08-27 10:36:10
添加以下css:
textarea.form-control{
position:absolute;
height: auto;
}
https://stackoverflow.com/questions/25524718
复制相似问题