如何在文本区域的placholder上换行 [英] how to line break on placholder of text area
问题描述
我希望在reactjs上的textarea占位符上换行
I am looking to line break on placeholder of textarea on reactjs
到目前为止,我已经尝试使用 \ n
,< br>
, nl2br
, \\ n
他们都不起作用
So far I have tried to use \n
, <br>
, nl2br
, \\n
and none of them worked
<Input type="textarea" name="txtarea" placeholder="Line1 \n Line2" />
当前输出即时消息与 Line1 \ n Line2
我的目标是将它们作为
Line1
Line2
推荐答案
换行符在< input>
元素的占位符属性中不起作用,但在< textarea>
元素.
Newlines do not work in the placeholder attribute of <input>
elements, but they work for the <textarea>
element.
但是,使用< input type ="textarea">
无效的标记,并且将由浏览器替换为< input type ="text">
.
However, using <input type="textarea">
is not valid markup and will be replaced by the browser to an <input type="text">
.
如果要多行输入,请改用< textarea>
.
If you want multi-line input, use a <textarea>
instead.
对于换行符,请在占位符中使用
和
HTML实体,它们是换行符
和换行符
字符:
For the newline, use the
and
HTML entities in your placeholder, which are the line feed
and the new line
characters:
<input type="text" placeholder="line line2">
<textarea placeholder="line1 line2"></textarea>
这篇关于如何在文本区域的placholder上换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!