登入注册页面html
时间: 2023-07-25 20:09:11 浏览: 105
以下是一个简单的登入注册页面的 HTML 代码示例:
```
<!DOCTYPE html>
<html>
<head>
<title>Login/Registration page</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
margin: 0;
padding: 0;
background-color: #f2f2f2;
font-family: Arial, sans-serif;
}
form {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
padding: 20px;
margin: 20px auto;
max-width: 400px;
}
h1 {
text-align: center;
margin-top: 0;
}
input[type=text], input[type=password] {
display: block;
margin: 10px 0;
padding: 10px;
border-radius: 5px;
border: none;
width: 100%;
box-sizing: border-box;
font-size: 16px;
}
input[type=submit] {
background-color: #4CAF50;
color: #fff;
border: none;
border-radius: 5px;
padding: 10px;
width: 100%;
cursor: pointer;
font-size: 16px;
}
input[type=submit]:hover {
background-color: #3e8e41;
}
.error {
color: red;
margin-bottom: 10px;
}
.success {
color: green;
margin-bottom: 10px;
}
.switch {
text-align: center;
margin-bottom: 10px;
}
.switch a {
color: #4CAF50;
text-decoration: none;
font-size: 14px;
}
</style>
</head>
<body>
<form action="login.php" method="post" id="login-form">
<h1>Login</h1>
<div class="error"></div>
<div class="success"></div>
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<input type="submit" value="Login">
<div class="switch">New user? <a href="#" id="register-link">Register here</a></div>
</form>
<form action="register.php" method="post" id="register-form" style="display: none;">
<h1>Register</h1>
<div class="error"></div>
<div class="success"></div>
<label for="new-username">Username:</label>
<input type="text" id="new-username" name="new-username" required>
<label for="new-password">Password:</label>
<input type="password" id="new-password" name="new-password" required>
<input type="submit" value="Register">
<div class="switch">Already a user? <a href="#" id="login-link">Login here</a></div>
</form>
<script>
// Switch between login and register forms
const loginForm = document.getElementById("login-form");
const registerForm = document.getElementById("register-form");
const loginLink = document.getElementById("login-link");
const registerLink = document.getElementById("register-link");
loginLink.addEventListener("click", function(event) {
event.preventDefault();
loginForm.style.display = "block";
registerForm.style.display = "none";
});
registerLink.addEventListener("click", function(event) {
event.preventDefault();
loginForm.style.display = "none";
registerForm.style.display = "block";
});
</script>
</body>
</html>
```
这个页面包括了一个登入表单和一个注册表单,用户可以通过点击链接在两个表单之间切换。您需要将表单的 action 属性设置为实际的登入和注册处理文件的 URL。注意,这只是一个示例,您需要根据自己的需求进行修改。