Line break in input value

2019-01-28 05:21发布

I am trying to add a couple of line breaks in an <input> value. &NewLine;, &#10;, &#13; &#10; and \n aren't working. Everything is still on the one line.

I haven't found an answer to this question amongst other questions that solves my problem. Thanks in advance.

标签: html input
2条回答
我想做一个坏孩纸
2楼-- · 2019-01-28 06:19

I don't actually think you can have line breaks for those types of form elements. You may have to use a <textarea> tag which allows for literal line breaks:

<textarea id="multiliner" name="multiliner">line1
line2
line3</textarea>

查看更多
唯我独甜
3楼-- · 2019-01-28 06:19

The HTML input elements, type text or something similar (such as email) will deliberately strip off all line breaks, so that’s not going to work.

The only form element which will accept line breaks is the textarea.

Incidentally, Clipboard.js works by creating a dummy textarea element to do its magic.

查看更多
登录 后发表回答