我有一个函数handleSubmit,其中包含e.preventDefault()
.
当我从<form>
的属性调用它时e.preventDefault()
工作onSubmit
如下所示:
<form className="popup" onSubmit={handleSubmit}>
但是当我在按钮中触发 handleSubmit 从onClick
属性Submit
时不起作用,如下所示:
<button className="submit-btn" type="submit" onSubmit={handleSubmit}>
handleSubmit()
功能:
const handleSubmit = (e) => {
e.preventDefault();
var today = new Date();
const newUser = {
id:
today.getHours() +
":" +
today.getMinutes() +
":" +
today.getMilliseconds(),
username: name,
email: email,
};
按钮没有提交事件。试试这个
<button className="submit-btn" type="submit" onClick={handleSubmit}>