如何限制我的文本区域溢出超出某些行?
我正在使用文本区域,因为我在增加行数时不需要滚动条。它应该可以调整大小。有没有可能的方法来做到这一点。
i am working with textarea in that i don't want scroll bar while increasing the number of rows. It should be resizable. Is there any possible way to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当用户输入更多文本时,您可以使用 JavaScript 增加
textarea
的高度。jsFiddle。
它似乎不想用该示例代码来缩小。我认为编写这些控件的大多数人都会生成一个带有
height: auto
的隐藏div
以及复制的所有字体样式 (font-size
, < code>font-family、line-height
、letter-spacing
等),然后更新div
的内部文本与textarea
的内容。然后,它根据该隐藏元素的高度设置textarea
的高度。You can use JavaScript to increase the height of the
textarea
as the user enters more text.jsFiddle.
It doesn't seem to want to shrink with that example code. I think most people who write these controls produce a hidden
div
withheight: auto
and all the font styles copied over (font-size
,font-family
,line-height
,letter-spacing
, etc) and then update thediv
's inner text with thetextarea
's contents. It then sets thetextarea
's height based on the height of this hidden element.