如果你只需要在前端展示密码是否匹配的信息而不涉及后端处理,可以通过纯HTML和JavaScript实现。以下是一个简单的例子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Check</title>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
</head>
<body>
<form id="registrationForm">
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<label for="confirmPassword">Confirm Password:</label>
<input type="password" id="confirmPassword" name="confirmPassword" required>
<div id="passwordMatchStatus"></div>
<button type="button" onclick="checkPassword()">Check Password</button>
</form>
<script>
function checkPassword() {
var password = $("#password").val();
var confirmPassword = $("#confirmPassword").val();
if (password == confirmPassword) {
$("#passwordMatchStatus").html("Passwords match!");
} else {
$("#passwordMatchStatus").html("Passwords do not match!");
}
}
</script>
</body>
</html>
在这个例子中,用户输入密码和确认密码后,点击"Check Password"按钮,JavaScript函数checkPassword将比较两个密码是否相等,并在页面上显示相应的消息。这里并没有涉及后端处理,而是在前端直接进行比较和展示。