how to word wrap in normal html textbox?

2020-04-11 18:53发布

问题:

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

make the text in textbox go word wrap

回答1:

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 Stewart for pointing out that rows and cols are required attributes to textarea.



回答2:

<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.



回答3:

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}}



回答4:

You will need to use a <textarea> with a wrap attribute. 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.



标签: html textbox