CSS Textarea在您键入文本时展开 [英] CSS Textarea that expands as you type text

查看:109
本文介绍了CSS Textarea在您键入文本时展开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Textarea,用户可以在其中输入文本。默认情况下,它的高度为17px。但是,如果用户插入大量文本,我想要相应地扩展文本区域。有没有办法这样做与CSS?非常感谢!

I have a Textarea where users can input text. By default it has a height of 17px. However if users insert a large amount of text, I want the text area to expand accordingly. Is there a way to do this with CSS ? Thanks in advance!!

推荐答案

这不能单独使用CSS。尝试自动增长jquery插件。
https:// github.com/jaz303/jquery-grab-bag/blob/master/javascripts/jquery.autogrow-textarea.js

This cannot be done with CSS alone. try the autogrow jquery plugin. https://github.com/jaz303/jquery-grab-bag/blob/master/javascripts/jquery.autogrow-textarea.js

您还可以查看自动增益演示这里 http://onehackoranother.com/projects/jquery/jquery -grab-bag / autogrow-textarea.html

You can also see autogrow demo here http://onehackoranother.com/projects/jquery/jquery-grab-bag/autogrow-textarea.html

它轻便且易于使用。下面是它的做法。定义您的textarea id。在< / body> 之前包含jquery js文件。然后在脚本标签之间,发出jquery命令 $(#txtInput)。autoGrow();

It's lightweight and easy to use. Here's how it's done. Define your textarea id. Include the jquery js file before </body>. Then between script tags, issue the jquery command $("#txtInput").autoGrow();

<body>
    <textarea id="txtInput"></textarea>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script> 

<script>
    $("#txtInput").autogrow();
</script>
</body>

这篇关于CSS Textarea在您键入文本时展开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆