以下是一个简单的注册页面示例,使用 HTML、CSS 和 JavaScript:
![](https://freee4u.com/assets/files/2023-07-18/1689708756-289946-1689708555596.png)
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>注册页</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>注册</h1>
<form onsubmit="return validateForm()">
<label for="username">用户名</label>
<input type="text" id="username" required>
<label for="email">邮箱</label>
<input type="email" id="email" required>
<label for="password">密码</label>
<input type="password" id="password" required>
<label for="confirmPassword">确认密码</label>
<input type="password" id="confirmPassword" required>
<button type="submit">注册</button>
</form>
</div>
<script src="script.js"></script>
</body>
</html>
style.css:
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
padding: 20px;
max-width: 400px;
width: 100%;
}
h1 {
text-align: center;
}
form {
display: flex;
flex-direction: column;
}
label {
margin-top: 10px;
}
input {
padding: 10px;
margin: 5px 0;
border: 1px solid #ccc;
border-radius: 3px;
}
button {
padding: 10px;
margin-top: 20px;
background-color: #3498db;
color: #fff;
border: none;
border-radius: 3px;
cursor: pointer;
}
button:hover {
background-color: #2980b9;
}
script.js:
function validateForm() {
const password = document.getElementById('password').value;
const confirmPassword = document.getElementById('confirmPassword').value;
if (password !== confirmPassword) {
alert('密码和确认密码不一致!');
return false;
}
return true;
}