使用html、css、JavaScript设计拥有用户名、密码、密码确认、邮箱、手机号码功能的登录注册页面
时间: 2023-09-30 21:09:08 浏览: 35
好的,下面是一个简单的示例代码:
HTML部分:
```html
<!DOCTYPE html>
<html>
<head>
<title>Login/Register Page</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container">
<div class="form-container">
<div class="form-title">
<h2>Login/Register</h2>
</div>
<div class="form-body">
<form id="login-form">
<h3>Login</h3>
<div>
<label for="username">Username: </label>
<input type="text" id="username" name="username">
</div>
<div>
<label for="password">Password: </label>
<input type="password" id="password" name="password">
</div>
<button type="submit">Login</button>
</form>
<form id="register-form">
<h3>Register</h3>
<div>
<label for="reg-username">Username: </label>
<input type="text" id="reg-username" name="reg-username">
</div>
<div>
<label for="reg-password">Password: </label>
<input type="password" id="reg-password" name="reg-password">
</div>
<div>
<label for="reg-confirm-password">Confirm Password: </label>
<input type="password" id="reg-confirm-password" name="reg-confirm-password">
</div>
<div>
<label for="email">Email: </label>
<input type="email" id="email" name="email">
</div>
<div>
<label for="phone">Phone: </label>
<input type="tel" id="phone" name="phone">
</div>
<button type="submit">Register</button>
</form>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
```
CSS部分:
```css
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: #f2f2f2;
}
.container {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
.form-container {
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
padding: 20px;
}
.form-title {
text-align: center;
margin-bottom: 20px;
}
.form-body {
display: flex;
flex-direction: column;
}
form h3 {
margin-bottom: 10px;
}
form div {
margin-bottom: 10px;
}
label, input {
display: block;
}
button[type="submit"] {
background-color: #4CAF50;
border: none;
color: white;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin-top: 10px;
border-radius: 5px;
cursor: pointer;
}
button[type="submit"]:hover {
background-color: #3e8e41;
}
```
JavaScript部分:
```javascript
const loginForm = document.getElementById('login-form');
const registerForm = document.getElementById('register-form');
loginForm.addEventListener('submit', login);
registerForm.addEventListener('submit', register);
function login(event) {
event.preventDefault();
const usernameInput = document.getElementById('username');
const passwordInput = document.getElementById('password');
// TODO: 实现登录功能
}
function register(event) {
event.preventDefault();
const usernameInput = document.getElementById('reg-username');
const passwordInput = document.getElementById('reg-password');
const confirmPasswordInput = document.getElementById('reg-confirm-password');
const emailInput = document.getElementById('email');
const phoneInput = document.getElementById('phone');
// TODO: 实现注册功能
}
```
注意,这只是一个简单的示例代码,实际上,要实现完整的登录注册功能需要考虑很多方面,比如安全性、输入验证、错误处理等等。