写一个好看html登入界面附加验证码
时间: 2023-12-19 07:05:10 浏览: 95
带有验证码的漂亮登录界面
以下是一个简单的 HTML 登录界面,包含验证码功能:
```html
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<style>
body {
background-color: #f2f2f2;
font-family: Arial, sans-serif;
}
form {
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0px 0px 10px 0px #ccc;
width: 400px;
margin: 50px auto;
}
h2 {
margin-top: 0;
text-align: center;
color: #333;
}
label {
display: block;
margin-bottom: 10px;
color: #666;
}
input[type="text"], input[type="password"] {
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
margin-bottom: 20px;
width: 100%;
font-size: 16px;
}
input[type="submit"] {
background-color: #4CAF50;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
margin-bottom: 10px;
}
.code-box {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 20px;
}
.code {
background-color: #fff;
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
font-size: 16px;
width: 60%;
}
.code-img {
height: 30px;
cursor: pointer;
}
</style>
</head>
<body>
<form>
<h2>Login</h2>
<label for="username">Username:</label>
<input type="text" id="username" name="username">
<label for="password">Password:</label>
<input type="password" id="password" name="password">
<div class="code-box">
<label for="code">Code:</label>
<input type="text" id="code" name="code" class="code">
<img src="#" alt="code" class="code-img">
</div>
<input type="submit" value="Login">
</form>
<script>
// 生成随机验证码
function generateCode() {
var code = "";
var codeLength = 6;
var charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < codeLength; i++) {
var randomChar = Math.floor(Math.random() * charSet.length);
code += charSet.charAt(randomChar);
}
return code;
}
// 更新验证码图片
function updateCode() {
var code = generateCode();
var codeImg = document.querySelector(".code-img");
var codeInput = document.querySelector(".code");
codeImg.src = "https://via.placeholder.com/150x30.png?text=" + code;
codeInput.value = "";
}
// 初始化
updateCode();
// 点击验证码图片更新验证码
document.querySelector(".code-img").addEventListener("click", function() {
updateCode();
});
</script>
</body>
</html>
```
该登录界面使用了简单的 HTML 和 CSS 样式,包含用户名、密码和验证码输入框,并且通过 JavaScript 动态生成随机验证码并显示在图片上。当用户点击验证码图片时,会生成新的验证码并更新到图片上。
阅读全文