简体   繁体   English

React.js:输入字段有值但显示为空

[英]Reactjs: input field has value but showing as empty

Facing a weird issue. 面对一个奇怪的问题。 I have an input field in my react app. 我的应用程序中有一个输入字段。 I am setting the value of my input field using the defaultValue prop. 我正在使用defaultValue设置输入字段的值。 But my input field is not populating. 但是我的输入字段没有填充。 Its showing as empty ( "" ). 它显示为 (“”)。 But i can see the value in its value attribute in the dom. 但是我可以在dom的value属性中看到该值。 在此处输入图片说明

Here are the react props of that input 这是该输入的反应道具

在此处输入图片说明

Any idea what i am missing here? 知道我在这里缺少什么吗?

You could use defaultValue only on uncontrolled components, but your input have onChange prop, and that makes it controlled. 您只能在不受控制的组件上使用defaultValue ,但是您的输入具有onChange defaultValue ,这使其受到控制。 You should set your default value through the value prop. 您应该通过value属性设置默认值。

https://reactjs.org/docs/uncontrolled-components.html - here some info about it. https://reactjs.org/docs/uncontrol-components.html-有关此的一些信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Reactjs 表单验证 - 用于输入类型编号的文本字段即使在从键盘退格后也不断显示单个值 - Reactjs Form Validations-for input type number the text field in constantly showing single value even after giving backspace from the keyboard 如果输入字段为空并且它有一个值检查它是否是数字,则什么都不做,如果不是则显示警报 - Do nothing if an input field is empty and if it has a value check to see if it is numeric and display an alert if it is not 如果未选中复选框或输入字段在 btn 单击时没有值,则在表行中显示错误 - Showing error in a table row if a checkbox is not checked or an input field has no value on btn click 如何在输入字段 reactjs 中设置输入字母数字值格式? - How to set input alphanumeric value format in input field reactjs? 如何用值替换空输入字段 - How to replace empty input field with a value 值属性为空,尽管输入字段不是 - value attribute empty although input field is not javascript输入未显示值,但控制台显示了它的值 - javascript input not showing value but console shows it has it 为什么输入字段值没有显示在表格中? - Why is the input field value not showing in the table? jQuery:计算值未显示在输入字段中 - Jquery: Calculated Value not showing in input field javascript object 字段输入值 [object Object] 代替字符串 Reactjs - javascript object field input value [object Object] instead of string Reactjs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM