Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.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
Javascript 如何在选择单选按钮时启用/禁用按钮?_Javascript_Reactjs_Redux_React Bootstrap_Redux Form - Fatal编程技术网

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} />