React 编辑具有值的输入元素
我有这个输入:
<input
type="text"
autoFocus
value={post.body}
/>
我希望用户能够编辑该值,我尝试设置 contentEditable 但它不起作用
i have this input:
<input
type="text"
autoFocus
value={post.body}
/>
i want the user to be able to edit the value, i tried to set contentEditable but it doesn't work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的代码中,您无法编辑值。
因为你设置了value,所以设置defaultValue。
In your code, you can not edit value.
Because you set value, so set defaultValue.
您必须在此输入上设置事件侦听器以捕获正在发生的变化。
您的数据应该是定义的状态变量,因为
在您的情况下,默认值可以是
post.body
,然后在输入组件中将所有内容连接在一起
You have to set event listener on this input to capture what is changing.
Your data should be state variable defined as
in your case the default value can be
post.body
and then in the input component connect all together