Html 如何制作 <input> 标签多行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7336743/
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
How to make a <input> tag multi line?
提问by GibboK
I would like to know if is possible to make a <input>
tag with appearance like multi-line (similar to the <TEXTAREA></TEXTAREA
>) using CSS or another option, unfortunately I can replace the tag with in my web application.
我想知道是否可以使用 CSS 或其他选项制作具有<input>
多行外观(类似于<TEXTAREA></TEXTAREA
>)的标签,不幸的是,我可以在我的 Web 应用程序中替换该标签。
<input id="uxMessage" validation="required" name="uxMessage" type="text" />
Many Thanks
非常感谢
回答by Michael Irigoyen
<input type="text" />
will always only be one line; You cannot force a multiple line behavior with CSS or JavaScript. You will need to use a <textarea>
instead of a <input>
.
<input type="text" />
永远只有一行;您不能使用 CSS 或 JavaScript 强制执行多行行为。您将需要使用 a<textarea>
而不是 a <input>
。
You could use jQuery and it's .replaceWith()
method to replace the targeted <input>
with a <textarea>
. however this has obvious caveats, such as those who visit your page without JavaScript on.
您可以使用 jQuery 及其.replaceWith()
方法将目标替换<input>
为<textarea>
. 但是,这有明显的警告,例如那些访问您的页面而没有启用 JavaScript 的人。
Example:
例子:
<input id="uxMessage" validation="required" name="uxMessage" type="text" />
$("#uxMessage").replaceWith('<textarea id="uxMessage" name="uxMessage"></textarea>');
回答by Clive
Not without some pretty hefty Javascript, Textarea is the only multi-line text input that I know of.
并非没有一些相当大的 Javascript,Textarea 是我所知道的唯一的多行文本输入。
Edit
编辑
Something like this might work with jQuery:
像这样的东西可能适用于 jQuery:
var textArea = jQuery('<textarea />').attr({'id': 'uxMessage', 'name': 'uxMessage'});
jQuery('#uxMessage').replaceWith(textArea);