调整文本区域大小以适合加载jquery上的所有文本 [英] Resize text area to fit all text on load jquery
问题描述
我知道有很多讨论,但我还没有找到解决方案来解决我的需求。基本上我需要自动增加文本区域,而不是在你输入时加载。我从数据库中提取内容,并根据用户的设置在文本区域上生成叠加层,但在执行此操作时,文本区域不可滚动,因此我需要自动调整这些内容以显示所有文本。
I understand there has been a lot of discussion on this but I have yet to find a solution to fix my needs. Basically I need to autogrow a text area not when you type but on load. I am pulling in content from a database and dependant on the user's settings an overlay is produced over the text area, but upon doing this the text areas are not scrollable therefore I need to autosize these to show all the text.
我尝试过scrollHeight,但由于屏幕上有多个文本框,因此效果不佳
I have tried scrollHeight but this is not working great as there are multiple text boxes on the screen
谢谢
推荐答案
试试这个
$("textarea").height( $("textarea")[0].scrollHeight );
更新
作为一个让它在旧的IE-s中工作的黑客只需在执行它之前添加一个非常短的延迟
As a hack to make it work in older IE-s just add a really short delay before executing it
window.setTimeout( function() {
$("textarea").height( $("textarea")[0].scrollHeight );
}, 1);
多个TEXTAREAS的更新
$("textarea").each(function(textarea) {
$this.height( $this[0].scrollHeight );
});
这篇关于调整文本区域大小以适合加载jquery上的所有文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!