【HTML5网页期末作业】基于HTML+CSS+JS实现宠物网站,表单展示登录页面,带JS密码验证
以下是一个简单的基于HTML、CSS和JavaScript的宠物网站登录页面示例。这个页面包含一个登录表单,并使用JavaScript验证密码的强度。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login to Pet Website</title>
<style>
body { font-family: Arial, sans-serif; }
.login-container { width: 300px; margin: 100px auto; padding: 20px; border: 1px solid #ccc; border-radius: 5px; }
.login-container h2 { text-align: center; }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; }
.form-group input[type="password"] { width: 100%; padding: 10px; }
.form-group .password-strength { display: none; padding: 5px; color: #fff; border-radius: 5px; }
.form-group .password-strength.weak { background-color: red; }
.form-group .password-strength.moderate { background-color: orange; }
.form-group .password-strength.strong { background-color: green; }
.form-group .password-strength.very-strong { background-color: blue; }
</style>
</head>
<body>
<div class="login-container">
<h2>Login to Pet Website</h2>
<form id="loginForm">
<div class="form-group">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<span class="password-strength"></span>
</div>
<div class="form-group">
<button type="submit">Login</button>
</div>
</form>
</div>
<script>
const loginForm = document.getElementById('loginForm');
const passwordInput = document.getElementById('password');
const passwordStrength = document.querySelector('.password-strength');
loginForm.addEventListener('submit', function(event) {
event.preventDefault();
// 这里可以添加登录逻辑,例如向服务器发送请求验证用户名和密码
checkPasswordStrength();
});
passwordInput.addEventListener('input', checkPasswordStrength);
function checkPasswordStrength() {
const password = passwordInput.value;
const strength = getPasswordStrength(password);
showPasswordStrength(strength);
}
function getPasswordStr
评论已关闭