简体   繁体   English

React Component在表单标签内不起作用

[英]React Component does not work inside form tag

I am trying to create an interactive form in React. 我正在尝试在React中创建一个交互式表单。

I encounter serious issues working with components within the form tag. 我在处理表单标签内的组件时遇到严重问题。 Both the component and the button executes all functions outside this form tag but not inside of it.. What do I miss? 组件和按钮都执行此Form标记之外的所有功能,但不能执行其中的所有功能。我想念什么? Thanks in advance 提前致谢

  <button type="button" onClick={this.addAbholer} >Click me</button>
  <Mycomp />
      <form id="form"  className="wizard-big">
          <Mycomp />
          <button type="button" onClick={this.addAbholer} >Click me</button>

Check this sample working code, i used the same code that you pasted, rendering the button and component inside form, all the events of child component getting triggered and on click of button is also working. 检查此示例工作代码,我使用了与您粘贴的代码相同的代码,在窗体内呈现了按钮和组件,所有触发了子组件的事件以及单击按钮时也都起作用。

 class App extends React.Component{ addAbholer = (e) => { console.log('inside App'); } render(){ return <form className="wizard-big"> <Mycomp /> <button type='button' onClick={this.addAbholer}>Click me</button> </form> } } class Mycomp extends React.Component{ click = () => { console.log('inside Mycomp'); } render(){ return <div onClick={this.click}>Click on Mycomp</div> } } ReactDOM.render(<App/>, document.getElementById('app')) 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> <div id='app'/> 

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM