html用户登录注册页面代码
创建一个基本的HTML用户登录和注册页面,
html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Login & Registration</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
form {
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
label {
display: block;
margin-bottom: 8px;
}
input {
width: 100%;
padding: 8px;
margin-bottom: 12px;
box-sizing: border-box;
}
button {
background-color: #4caf50;
color: #fff;
padding: 10px 15px;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.form-switch {
text-align: center;
margin-top: 10px;
}
.form-switch a {
color: #1e88e5;
text-decoration: none;
cursor: pointer;
}
.form-switch a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div>
<form id="loginForm">
<h2>Login</h2>
<label for="loginUsername">Username:</label>
<input type="text" id="loginUsername" name="loginUsername" required>
<label for="loginPassword">Password:</label>
<input type="password" id="loginPassword" name="loginPassword" required>
<button type="submit">Login</button>
<div class="form-switch">
<a onclick="showRegisterForm()">Don't have an account? Register here.</a>
</div>
</form>
<form id="registerForm" style="display: none;">
<h2>Register</h2>
<label for="registerUsername">Username:</label>
<input type="text" id="registerUsername" name="registerUsername" required>
<label for="registerPassword">Password:</label>
<input type="password" id="registerPassword" name="registerPassword" required>
<button type="submit">Register</button>
<div class="form-switch">
<a onclick="showLoginForm()">Already have an account? Login here.</a>
</div>
</form>
</div>
<script>
function showRegisterForm() {
document.getElementById('loginForm').style.display = 'none';
document.getElementById('registerForm').style.display = 'block';
}
function showLoginForm() {
document.getElementById('loginForm').style.display = 'block';
document.getElementById('registerForm').style.display = 'none';
}
</script>
</body>
</html>
这个例子中包含了一个简单的登录表单和注册表单,以及在两者之间切换的链接。在实际应用中,你可能需要与服务器进行通信以验证用户的凭据,并采取适当的安全措施。此外,
在实际应用中,你可能需要将这个前端页面与后端服务器进行连接,以便验证用户的身份和处理注册请求。