【发布时间】:2021-06-14 03:45:01
【问题描述】:
我试图在一个页面中显示登录和注册,我可以单击显示登录表单的登录链接。
问题是当我点击登录链接<a href="" onClick={() => setlogin(true)}>login?</a>时,页面会加载1s然后返回注册表单。
代码:
import React, { ReactElement, Fragment, useState } from "react";
function LoginSignUp() {
const [login, setlogin] = useState(false);
return (
<Fragment>
{login ? (
<form className="form-signin">
<input
type="email"
id="inputEmail"
className="form-control"
placeholder="Email address"
required
/>
<input
type="password"
id="inputPassword"
className="form-control"
placeholder="Password"
required
/>
<button type="submit">Sign in</button>
</form>
) : (
<form className="form-signup">
<input
type="text"
name="username"
className="form-control"
placeholder="Username"
required
/>
<input
type="email"
name="email"
className="form-control"
placeholder="Email address"
required
/>
<input
type="password"
name="password"
className="form-control"
placeholder="Password"
required
/>
<input
type="password"
name="password2"
className="form-control"
placeholder="Confirm Password"
required
/>
<button type="submit">Sign Up</button>
</form>
)}
<p id="logintxt">
Do you already have an account? ,{" "}
<a href="" onClick={() => setlogin(true)}>
login?
</a>
</p>
</Fragment>
);
}
【问题讨论】:
标签: javascript html reactjs dom jsx