[英]Is there any way to change value of textarea with HTML
I'm trying to make markdown editor with auto resizable textarea. 我正在尝试使Markdown编辑器具有可自动调整大小的textarea。
I'm using marked library. 我正在使用标记的库。 But when I change value with
value={marked(this.props.text)}
, it outputs like: <p>Hello</p>
但是,当我使用
value={marked(this.props.text)}
更改值时,它的输出类似于: <p>Hello</p>
I can't even use dangerouslySetInnerHTML
or innerHTML
property since textarea doesn't render HTML. 由于textarea不会呈现HTML,因此我什至不能使用
dangerouslySetInnerHTML
地设置内部HTML或innerHTML
属性。
When I use elements such as p, It doesn't look like textarea. 当我使用诸如p之类的元素时,它看起来不像textarea。
Can someone give me a hint? 有人可以给我提示吗?
I've solved it, see this post 我已经解决了,请看这篇文章
In other to make the element look like textarea
, you should translate a carriage return into a br
html tag. 另外,为了使元素看起来像
textarea
,您应该将回车符转换为br
html标记。
In this post:
You could just apply CSS
white-space:pre
on the element, exactly like the HTMLtextarea
element is internally doing:您可以仅将CSS
white-space:pre
应用于元素,就像HTMLtextarea
元素在内部进行的操作一样:
<span style="white-space:pre">your text \n will \n be \n on multiple \n lines</span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.