如何在普通的 html 文本框中自动换行?

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

how to word wrap in normal html textbox?

htmltextbox

提问by dexter

i have this text box

我有这个文本框

<p>Event Data :<input  id="data" type="text" wrap="true" value="{{data}}" 
            style="width: 757px; height: 170px" />
    </p>   

i want it to be multiline i can't use asp:textbox is it possible to use exact textbox and make it multiline or

我希望它是多行的我不能使用 asp:textbox 是否可以使用精确的文本框并使其成为多行或

make the text in textbox go word wrap

使文本框中的文本自动换行

回答by Dominic Rodger

How about this:

这个怎么样:

<p>Event Data:
<textarea id="data" style="width: 757px; height: 170px" rows="10" cols="80">{{data}}</textarea>
</p>

Hat tip (and +1) to Stewartfor pointing out that rowsand colsare required attributes to textarea.

斯图尔特的帽子提示(和 +1)指出rowscolstextarea.

回答by Stewart

<p>Event Data:
<textarea id="data" rows="10" cols="80">{{data}}</textarea>
</p>

rows and cols are required attributes. Don't ask me why. And if you're going to set the size in CSS, it's generally better to do it in em or % rather than px.

行和列是必需的属性。不要问我为什么。如果您打算在 CSS 中设置大小,通常最好使用 em 或 % 而不是 px。

回答by Dan Gayle

If you mean that you want your text values to display as multi-lines, use add a white-space: pre;style to the textarea element, making sure to put put the proper line-breaks into the returned {{data}}

如果您的意思是希望文本值显示为多行,请使用white-space: pre;向 textarea 元素添加样式,确保将正确的换行符放入返回的{{data}}

回答by Pekka

You will need to use a <textarea>with a wrapattribute. It is not in any HTML standard but to my knowledge the settings "soft", "hard" and "off" work in all major browsers. Definitely in IE. Firefox seems to require a "cols" setting for wrap to work, though.

您将需要使用<textarea>带有wrap属性的a 。它不在任何 HTML 标准中,但据我所知,设置“软”、“硬”和“关闭”在所有主要浏览器中都有效。绝对在IE 中。不过,Firefox 似乎需要“cols”设置才能使 wrap 工作。