Javascript 如何在选择单选按钮时启用/禁用按钮?
我是新手。目前在我的应用程序中,我想启用和禁用选择单选按钮上的按钮。下面是我的代码:Javascript 如何在选择单选按钮时启用/禁用按钮?,javascript,reactjs,redux,react-bootstrap,redux-form,Javascript,Reactjs,Redux,React Bootstrap,Redux Form,我是新手。目前在我的应用程序中,我想启用和禁用选择单选按钮上的按钮。下面是我的代码: class Radiosample extends React.Component { render() { <table> <tbody> <tr> <td> <Field name="radio1" component="input" id="radio
class Radiosample extends React.Component {
render() {
<table>
<tbody>
<tr>
<td>
<Field name="radio1" component="input" id="radio1" type="radio"/> // On check of this radio button below button should enable..
</td>
<Button name="button" id="btn">Click Me</Button>
</tr>
</tbody>
</table>
}
}
export default Radiosample
class-Radiosample.Component{
render(){
//检查此单选按钮时,下面的按钮应启用。。
点击我
}
}
导出默认无线电采样
谢谢不太一般,但这件简单的事情不应该奏效吗
class Radiosample extends React.Component {
function disableButton() {
document.getElementById("btn").disabled = true;
}
render() {
<table>
<tbody>
<tr>
<td>
<Field name="radio1" onclick="this.disableButton()" component="input" id="radio1" type="radio"/> // On check of this radio button below button should enable..
</td>
<Button name="button" id="btn">Click Me</Button>
</tr>
</tbody>
</table>
}
}
export default Radiosample
class-Radiosample.Component{
函数禁用按钮(){
document.getElementById(“btn”).disabled=true;
}
render(){
//检查此单选按钮时,下面的按钮应启用。。
点击我
}
}
导出默认无线电采样
您应该使用状态,否则页面将不会重新呈现
所以onClick或onChange事件需要更新状态
setButtonDisability = (event: React.MouseEvent<HTMLInputElement>) => this.setState({ isButtonDisabled: /* value from event target */ })
您应该明确检查。可能的副本
<Button name="button" disabled={this.state.isButtonDisabled} />