React - 防止表单提交 [英] React - Preventing Form Submission

查看:44
本文介绍了React - 防止表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试验 React.在我的实验中,我使用的是 Reactstrap 框架.当我点击一个按钮时,我注意到提交了 HTML 表单.有没有办法在单击按钮时阻止表单提交?

I've been experimenting with React. In my experiement, I'm using the Reactstrap framework.When I click a button, I've noticed that the HTML form submits. Is there a way to prevent form submission when a button is clicked?

我在这里重新创建了我的问题.我的表单非常基本,如下所示:

I've recreated my issue here. My form is pretty basic and looks like this:

<Form>
  <h3>Buttons</h3> 
  <p>
    <Button color="primary" onClick={this.onTestClick}>primary</Button>&nbsp;
  </p>
</Form>

我错过了什么?

推荐答案

我认为首先值得注意的是,如果没有 javascript(纯 html),form 元素在单击 <input type="submit" value="submit form">

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆