创建一个宽度自动扩展的文本框?
我将如何创建一个具有自动扩展宽度以适应其内容的文本框?
我不断找到大量关于基于高度的扩展的信息,但关于宽度的信息却很少。
我还希望它适用于页面上的每个文本框,而不仅仅是特定的文本框。
How would I go about creating a textbox with an auto-expanding width to fit it's content?
I keep finding plenty of info on height based expansions but not much on width.
I'd also like it to apply to every textbox on the page and not just specific ones.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不确定这是否是您的想法,但这不应该起作用吗?
Not sure if this is what you had in mind, but shouldn't this work?
如果您想要退格键处理,请使用此:
如果您想要退格键处理并忽略箭头键,请使用此:
If you want backspace key handling use this:
If you want backspace key handling and to ignore arrow keys use this one:
我认为更好的解决方案是检查文本的长度并在文本太长时修改文本框,而不是检查不应触发扩展的每种类型的关键事件。一个例子:
I think a better solution would be to check the length of the text and modify the textbox if the text was too long rather than checking for every type of key event that shouldn't trigger an expansion. An example: