gpt4 book ai didi

javascript - react : setting the disabled attribute based on a state

转载 作者:可可西里 更新时间:2023-11-01 01:46:23 24 4
gpt4 key购买 nike

我想根据组件的状态在 Button 上设置禁用属性,如下所示:

render() {
return (
<button type="button" {this.state.submitting ? 'disabled' : ''}
onClick={ this.handleSubmit }>Submit</button>
);
}

目前我在开头收到意外的 token 错误{,我错过了什么?

最佳答案

你可以通过 bool 值设置disabled属性,像这样

<button
type="button"
disabled={this.state.submitting}
onClick={this.handleSubmit}
>
Submit
</button>

Example

关于javascript - react : setting the disabled attribute based on a state,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33673520/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com