如何使用 jQuery 使文本区域自动展开?
我有一个用于解释 session 议程的文本框,所以当我的议程文本不断扩大该文本框区域时,我想扩展该文本框。
最佳答案
如果你不想要插件,有一个非常简单的解决方案
$("textarea").keyup(function(e) {
while($(this).outerHeight() < this.scrollHeight + parseFloat($(this).css("borderTopWidth")) + parseFloat($(this).css("borderBottomWidth"))) {
$(this).height($(this).height()+1);
};
});
查看它在 jsFiddle I used to answer another textarea question here 中的工作情况.
要回答反向操作或在删除文本时使其变小的问题:jsFiddle
And if you do want a plugin
关于jquery - 使用 jQuery 自动扩展文本区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2948230/