JQuery TextArea AutoGrow 插件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5050801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:27:18  来源:igfitidea点击:

JQuery TextArea AutoGrow Plugin

jquery

提问by Hirvesh

I'm trying to find the best textarea autogrow plugin. I need one which resizes the textarea even when I paste into it. Any idea?

我试图找到最好的 textarea 自动增长插件。我需要一个即使我粘贴到文本区域也能调整它的大小。任何的想法?

采纳答案by Manish Trivedi

Why not use it?? http://plugins.jquery.com/project/autogrowtextarea

为什么不用它?? http://plugins.jquery.com/project/autogrowtextarea

Or another updated version of this plugin here: https://github.com/ro31337/jquery.ns-autogrow

或者这里插件的另一个更新版本:https: //github.com/ro31337/jquery.ns-autogrow

回答by labilbe

Elastic is a very good one, and it handles CTRL + V cases too.

Elastic 是一款非常好的产品,它也可以处理 CTRL + V 情况。

You can visit the websiteand try out a demo.

您可以访问该网站并试用演示。

回答by Pete Montgomery

This is the one I ended up using. Working great so far!

这是我最终使用的一种。到目前为止工作得很好!

http://www.Hymanlmoore.com/autosize/

http://www.Hymanlmoore.com/autosize/

The JQuery Elastic plugin is slow and didn't work for me in IE8.

JQuery Elastic 插件很慢,在 IE8 中对我不起作用。

回答by Gaucho_9

I used the following method, in jQuery.

我使用了以下方法,在jQuery.

setInterval(function(){
      $(name_textarea).css('height', $(name_textarea)[0].scrollHeight+2+'px')
},100);

Try it, you could possibly change the scrollHeightto obtain the best results.

试试吧,你可能会改变scrollHeight以获得最好的结果。

回答by john

You can try Advanced Textarea. Download from http://www.jscripts.info

您可以尝试高级文本区域。从http://www.jscripts.info下载

  • Auto-Height Textarea
  • Returns Plain Text and HTML Content
  • Automatic URL and Email recognition
  • HTML Tags Filter
  • 自动高度文本区域
  • 返回纯文本和 HTML 内容
  • 自动 URL 和电子邮件识别
  • HTML 标签过滤器

回答by crisc82

"I need one which resizes the textarea even when I paste into it"

“即使我粘贴到文本区域,我也需要一个调整文本区域大小的工具”

this method also listen for copy/paste events: https://stackoverflow.com/a/5346855/4481831

此方法还侦听复制/粘贴事件:https: //stackoverflow.com/a/5346855/4481831

I think on modern browsers those events can be replaced with "input" event, but on older browser this method will not work.

我认为在现代浏览器上,这些事件可以用“输入”事件替换,但在旧浏览器上,这种方法不起作用。

回答by Bud Damyanov

Auto-expand of text area can be accomplished withoutplugin. For example:

无需插件即可实现文本区域的自动扩展。例如:

 var change_textarea = function() {
   jQuery('#your_textarea').on( 'change keyup keydown paste cut', 'textarea', 
   function(){
     jQuery(this).height(0).height(this.scrollHeight);
   }).find( 'textarea' ).change();  
 }  

And do not forget to call the function on document ready:

并且不要忘记在文档就绪时调用函数:

  jQuery(document).ready(function() {
     change_textarea();
  )};

回答by Andrew Dryga

i made another one plugin to do this, check it here: https://github.com/AndrewDryga/jQuery.Textarea.Autoresize

我制作了另一个插件来做到这一点,请在此处查看:https: //github.com/AndrewDryga/jQuery.Textarea.Autoresize

回答by Brave Dave

Here is another plug, that also support horizontal growing of text areas:

这是另一个插件,它也支持文本区域的水平增长:

https://github.com/dgbeck/jquery.autogrow-textarea

https://github.com/dgbeck/jquery.autogrow-textarea

It is also based on the "mirror" approach but falls back to simple math in IE 8 and lower, since the mirror approach leads to textareas that grow too quickly in IE <= 8.

它也基于“镜像”方法,但在 IE 8 及更低版本中退回到简单数学,因为镜像方法导致文本区域在 IE <= 8 中增长过快。