亲爱的C知道,你能否用HTML做一个一进入就弹出需要输入正确密码的输入框,如果输入正确就提示登陆成功,如果错误就用红色字体显示错误请检查,希望你可以设置成2个密码,ui请设计的好看点。
时间: 2023-06-18 13:06:10 浏览: 39
当然可以,以下是一个简单的HTML代码实现:
```html
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<style>
body {
background-color: #f2f2f2;
font-family: Arial, sans-serif;
}
.container {
margin-top: 50px;
text-align: center;
}
.form {
display: inline-block;
background-color: white;
border-radius: 5px;
padding: 20px;
box-shadow: 0px 0px 10px rgba(0,0,0,0.2);
text-align: center;
}
input[type=text], input[type=password] {
margin-top: 10px;
width: 200px;
height: 30px;
padding: 5px;
border-radius: 3px;
border: none;
box-shadow: 0px 0px 2px rgba(0,0,0,0.2);
font-size: 16px;
color: #333;
}
input[type=submit] {
margin-top: 20px;
width: 100px;
height: 30px;
border-radius: 3px;
border: none;
background-color: #4CAF50;
color: white;
font-size: 16px;
cursor: pointer;
}
.error {
color: red;
margin: 10px 0px;
}
</style>
</head>
<body>
<div class="container">
<div class="form">
<h1>Login</h1>
<form onsubmit="return validateForm()">
<label for="password1">Password 1: </label><br>
<input type="password" id="password1" name="password1"><br>
<label for="password2">Password 2: </label><br>
<input type="password" id="password2" name="password2"><br>
<span id="error" class="error"></span><br>
<input type="submit" value="Submit">
</form>
</div>
</div>
<script>
function validateForm() {
var password1 = document.getElementById("password1").value;
var password2 = document.getElementById("password2").value;
var errorSpan = document.getElementById("error");
if (password1 === "" || password2 === "") {
errorSpan.innerHTML = "Please fill in both passwords.";
return false;
}
if (password1 !== password2) {
errorSpan.innerHTML = "Passwords do not match. Please check.";
return false;
}
alert("Login successful!");
return true;
}
</script>
</body>
</html>
```
这个代码会创建一个登录页面,其中包含两个密码框和一个提交按钮。当用户点击提交按钮时,`validateForm()` 函数会被调用来验证用户输入的密码是否匹配。如果两个密码都输入了并且匹配,则会弹出一个提示框,显示“登录成功!”。如果有任何输入错误,则会在页面上显示错误消息。