帮我生成一个html页面,页面元素有两个输入框,一个显示输入接收验证码的邮箱账号,一个显示输入验证码,两个按钮,一个获取验证码,一个登录,然后就是使用ajax向后端发送数据要求发送方式都是post,点击获取验证码后按钮变为不可使用并显示在60秒后重试,整个页面参考qq邮箱登录界面
时间: 2023-09-30 19:09:40 浏览: 132
好的,以下是一个简单的HTML页面,包含你所需要的所有元素和功能:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Email Verification Code</title>
<style>
body {
background-color: #f5f5f5;
font-family: 'Arial', sans-serif;
}
.container {
margin: 50px auto;
width: 450px;
padding: 30px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0px 0px 10px #888;
}
h1 {
text-align: center;
margin-bottom: 30px;
}
input {
display: block;
width: 100%;
margin-bottom: 20px;
padding: 10px;
font-size: 16px;
border: none;
border-radius: 5px;
box-shadow: 0px 0px 5px #ccc;
}
.btn {
display: inline-block;
padding: 10px 20px;
background-color: #007aff;
color: #fff;
font-size: 16px;
border: none;
border-radius: 5px;
cursor: pointer;
}
.btn.disabled {
background-color: #ccc;
cursor: not-allowed;
}
.error {
color: #ff0000;
font-size: 14px;
}
</style>
</head>
<body>
<div class="container">
<h1>Email Verification Code</h1>
<form id="verification-form">
<label for="email">Email Address:</label>
<input type="email" id="email" name="email" required>
<label for="code">Verification Code:</label>
<input type="text" id="code" name="code" required>
<div id="error-message" class="error"></div>
<button id="btn-get-code" class="btn">Get Verification Code</button>
<button id="btn-login" class="btn disabled">Login</button>
</form>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
var timer;
var countdown = 60;
var isSending = false;
// Disable the login button by default
$('#btn-login').attr('disabled', true);
// Handle form submission
$('#verification-form').submit(function(e) {
e.preventDefault();
var email = $('#email').val();
var code = $('#code').val();
$.post('/verify', { email: email, code: code }, function(response) {
if (response.success) {
// Redirect to the dashboard page
window.location.href = '/dashboard';
} else {
// Display the error message
$('#error-message').text(response.message);
}
});
});
// Handle the Get Verification Code button click
$('#btn-get-code').click(function() {
if (isSending) {
return;
}
var email = $('#email').val();
$.post('/send-code', { email: email }, function(response) {
if (response.success) {
// Disable the button and start the countdown timer
isSending = true;
$('#btn-get-code').addClass('disabled');
timer = setInterval(function() {
countdown--;
if (countdown === 0) {
clearInterval(timer);
isSending = false;
countdown = 60;
$('#btn-get-code').removeClass('disabled');
$('#btn-get-code').text('Get Verification Code');
} else {
$('#btn-get-code').text(countdown + ' seconds left');
}
}, 1000);
} else {
// Display the error message
$('#error-message').text(response.message);
}
});
});
// Handle input changes
$('#email, #code').on('input', function() {
var email = $('#email').val();
var code = $('#code').val();
if (email && code) {
$('#btn-login').removeClass('disabled');
$('#btn-login').attr('disabled', false);
} else {
$('#btn-login').addClass('disabled');
$('#btn-login').attr('disabled', true);
}
});
});
</script>
</body>
</html>
```
请注意,这只是一个示例页面,并不包含后端代码。你需要根据你的需求修改和添加必要的代码。此外,你还需要将 jQuery 库文件链接到你的页面中,以便使用 AJAX 功能。
阅读全文