html+css+js设计修改密码页面代码
时间: 2024-12-17 11:24:05 浏览: 6
HTML、CSS和JavaScript可以组合创建一个基本的修改密码页面。这里是一个简单的示例:
**HTML部分 (index.html)**:
```html
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="styles.css">
<title>修改密码</title>
</head>
<body>
<div class="container">
<h1>修改密码</h1>
<form id="passwordForm">
<label for="oldPassword">旧密码:</label>
<input type="password" id="oldPassword" name="oldPassword" required><br>
<label for="newPassword">新密码:</label>
<input type="password" id="newPassword" name="newPassword" pattern=".{6,}" required><br>
<label for="confirmPassword">确认新密码:</label>
<input type="password" id="confirmPassword" name="confirmPassword" pattern=".{6,}" required><br>
<button type="submit">提交</button>
</form>
<p id="errorMessages"></p>
</div>
<script src="scripts.js"></script>
</body>
</html>
```
**CSS部分 (styles.css)**:
```css
.container {
width: 400px;
margin: auto;
padding: 20px;
border: 1px solid #ccc;
}
form label {
display: block;
margin-bottom: 5px;
}
button {
margin-top: 10px;
}
```
**JavaScript部分 (scripts.js)**:
```javascript
document.getElementById('passwordForm').addEventListener('submit', function(event) {
event.preventDefault(); // 阻止表单默认提交
const oldPassword = document.getElementById('oldPassword').value;
const newPassword = document.getElementById('newPassword').value;
const confirmPassword = document.getElementById('confirmPassword').value;
if (newPassword !== confirmPassword) { // 检查新密码是否一致
document.getElementById('errorMessages').textContent = '新密码与确认密码不一致';
} else {
// 这里只是一个示例,实际应用中应连接到服务器验证密码更改
console.log('密码更改信息:', { oldPassword, newPassword });
document.getElementById('errorMessages').textContent = '密码已成功更新';
}
});
```
阅读全文