简体   繁体   English

html / JavaScript-空间用完时将输入文本转换为textarea

[英]html / javascript - Turn input text into textarea when space runs out

So I have a text input. 所以我有一个文本输入。

<input type="text" id="myText" style="width: 400px; height: 20px;">

I want to turn it into a textarea when there is no longer enough space to type stuff in. 当空间不足以输入内容时,我想将其转换为文本区域。

Once the text input has run out of space, I want to change it to something like this: 一旦文本输入空间不足,我想将其更改为以下内容:

<textarea id="myText" style="width: 400px; height: 40px; resize: none;"></textarea>

And when the space in the textarea has run out, its height will be changed again: 当文本区域中的空间用完时,其高度将再次更改:

<textarea id="myText" style="width: 400px; height: 60px; resize: none;"></textarea>

The main problem that I am facing is turning the original input text into a textarea. 我面临的主要问题是将原始输入文本转换为文本区域。 Is there an easy way besides trial and error to really detect if the space has run out? 除了反复试验之外,还有一种简便的方法可以真正检测出空间是否用完了? And how do I change my text input into a textarea once the space has run out? 一旦空间用完,如何将文本输入更改为文本区域?

Thanks. 谢谢。

I think having two different elements complicates things, have a look at only having a textarea element and then expand it as needed. 我认为拥有两个不同的元素会使事情变得复杂,只考虑拥有一个textarea元素,然后根据需要对其进行扩展。 There's a jQuery plugin you might want to look into if you're ok with using jQuery: http://www.jacklmoore.com/autosize/ 如果您可以使用jQuery,可以尝试使用一个jQuery插件: http : //www.jacklmoore.com/autosize/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用javascript检测textarea /文本输入中的HTML标签,但它应支持通用&gt;和 - Detect HTML tags in textarea/text input with javascript, but it should supports the common > and < 当用户停止选择输入或文本区域的文本时,Javascript 中是否存在事件? - Exist an event in Javascript when the user stop select the text of a input or textarea? 当javascript中有输入更改时,HTML textarea中的文本自动更改 - text change inHTML textarea automatically when ever there is a input change in javascript 在HTML textArea中的每个文本后添加空格 - Adding a space after each text in a HTML textArea HTML表单:在输入中显示文本(文本区域) - HTML forms: display a text in an input (textarea) 在工具栏中选择文本后的HTML工具提示 <input> 或在 <textarea> - HTML Tooltip after selecting text in an <input> or in a <textarea> 在提交时将文本输入注释textarea html / jquery - input text into a comment textarea html/jquery on submit 使用javascript html实时预览textarea输入 - Live preview of textarea input with javascript html 使用JavaScript将输入字段文本插入到textarea中 - Inserting input field text into textarea with JavaScript 通过输入更改ID将HTML中的文本作为函数传递到Javascript中 - Getting Text out of HTML into Javascript as a Function with Input Changing IDs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM