React - Preventing Form Submission

前端 未结 11 910
一个人的身影
一个人的身影 2020-11-27 06:35

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 t

11条回答
  •  面向向阳花
    2020-11-27 07:14

    I think it's first worth noting that without javascript (plain html), the form element submits when clicking either the or . In javascript you can prevent that by using an event handler and calling e.preventDefault() on button click, or form submit. e is the event object passed into the event handler. With react, the two relevant event handlers are available via the form as onSubmit, and the other on the button via onClick.

    Example: http://jsbin.com/vowuley/edit?html,js,console,output

提交回复
热议问题