Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 当输入字段为空而未使用处理程序时禁用按钮_Reactjs_Button - Fatal编程技术网

Reactjs 当输入字段为空而未使用处理程序时禁用按钮

Reactjs 当输入字段为空而未使用处理程序时禁用按钮,reactjs,button,Reactjs,Button,当输入字段为空时,我尝试禁用一个按钮,而不使用处理程序。 在检查条件之前,我只想在输入更改时启用按钮(尚未检查输入内容),但我确实看到状态更改(我可以在警报中看到),但按钮从未启用(我可以在调试器中看到) 构造函数(道具){ 超级(道具); this.state={'enableAdd':false} } 文本:{this.state.enableAdd=true;警报(this.state.enableAdd)}/> 添加 有什么想法吗 谢谢您需要检查,如何更新状态值? 而不是直接更改状态值

当输入字段为空时,我尝试禁用一个按钮,而不使用处理程序。 在检查条件之前,我只想在输入更改时启用按钮(尚未检查输入内容),但我确实看到状态更改(我可以在警报中看到),但按钮从未启用(我可以在调试器中看到)

构造函数(道具){
超级(道具);
this.state={'enableAdd':false}
}
文本:{this.state.enableAdd=true;警报(this.state.enableAdd)}/>
添加
有什么想法吗


谢谢

您需要检查,如何更新状态值?

而不是直接更改状态值
this.state.enableAdd=true使用
设置状态

像这样:

this.setState({enableAdd=true});
检查
React
中的如何使用
状态
,了解其他详细信息

检查问题的工作示例:

类应用程序扩展了React.Component{
建造师(道具){
超级(道具);
this.state={'enableAdd':false};
this.addTODO=this.addTODO.bind(this);
}
addTODO(){
console.log('clicked');
}
render(){
返回
this.setState({enableAdd:e.target.value!=''})}/>
添加
}   
}
ReactDOM.render(,document.getElementById('root'))

您需要检查,如何更新状态值?

而不是直接更改状态值
this.state.enableAdd=true使用
设置状态

像这样:

this.setState({enableAdd=true});
检查
React
中的如何使用
状态
,了解其他详细信息

检查问题的工作示例:

类应用程序扩展了React.Component{
建造师(道具){
超级(道具);
this.state={'enableAdd':false};
this.addTODO=this.addTODO.bind(this);
}
addTODO(){
console.log('clicked');
}
render(){
返回
this.setState({enableAdd:e.target.value!=''})}/>
添加
}   
}
ReactDOM.render(,document.getElementById('root'))