Html 我可以让 <input> 框具有换行的文本吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5981791/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 08:34:08  来源:igfitidea点击:

Can I make an <input> box have text that wraps?

htmlcss

提问by MikeSwanson

I have an

我有一个

<input type="text" /> 

box. The data in my box is quite long so I set the height to 100px. However the text just goes from left to right and does not wrap. Is there any way I could make it wrap?

盒子。我的框中的数据很长,所以我将高度设置为 100px。然而,文本只是从左到右,不会换行。有什么办法可以让它包裹起来吗?

Hoping for some good suggestions.

希望有好的建议。

Thanks,

谢谢,

回答by mellamokb

You need to use a <textarea>instead for input text that wraps.

您需要使用 a<textarea>代替换行的输入文本。

回答by H?vard S

For multiline input and wrapping text, use a <textarea>.

对于多行输入和换行文本,请使用<textarea>.

回答by Isaac Truett

No, you can't make an input element do that. Use textarea instead.

不,你不能让输入元素这样做。使用 textarea 代替。

回答by Raghav

With the style attr, or with CSS, you can do this:

使用 styleattr或 CSS,您可以执行以下操作:

<textarea 
    id="temp" 
    style="white-space: pre-wrap; height: 100px; width: 500px;"
>This is my text box. And it can wrap.</textarea>

The same thing can be done in jQuery with:

同样的事情可以在 jQuery 中完成:

$('#dom_id').attr("style", "white-space: pre-wrap");

This will hold for both textbox and text area.

这将适用于文本框和文本区域。