单击提交按钮后重置输入表单

时间:2021-07-21 18:43:37

标签: javascript reactjs forms input

我遇到了一个烦人的问题。

之后我找不到清除表单的方法

在这个反应组件中点击提交按钮。我几乎什么都试过了。

有人能做到吗?

我尝试了 window.local.reload、reset 和所有其他事情。

import emailjs from "emailjs-com";
import "./style.css";
import React from "react";

const About = () => {
  function sendEmail(e) { 
    e.preventDefault()
    document.getElementsByClassName("form-control").value=" " ;

    emailjs
      .sendForm(
        "",
        "",
        e.target,
        ""
      )
      .then((res) => {
        console.log(res);
      })
      .catch((err) => console.log(err));
  }
  return (
    <div className="contact">
      <div
        className="container"
        style={{
          marginTop: "50px",
          width: "50%",
        }}
      >
        <h1 style={{ marginTop: "25px" }}>Contact Form</h1>
        <form className="form-style-6" onSubmit={sendEmail}>
          <label>name</label>
          <input  type="text" name="name" className="form-control" />

          <label>Email</label>
          <input  type="email" name="user_email" className="form-control"  />

          <label>Message</label>
          <textarea  name="message" rows="4" className="form-control" />
          <input
            type="submit"
            
            className="form-control btn btn-primary"
            style={{ marginTop: "30px" }}
            >
              
          </input>
        </form>
      </div>
      
    </div>
  );
};

export default About;

0 个答案:

没有答案