请按照我的意愿优化下面的代码,要求能自动适应手机等界面,全局字体为楷体<!DOCTYPE html> <html> <head> <meta lang="zn"> <meta charset="utf-8"> <title>文件实验室账号登录</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> </head> <body> <form id="login-form" action="#"> <label for="email"></label> <input type="email" id="email" name="email" placeholder="在此输入邮箱账号"> <button type="button" id="get-code-btn">获取验证码</button> <br><br> <label for="code"></label> <input type="text" id="code" name="code" placeholder="在此输入收到的验证码"> <button type="submit">登录</button> </form> <script> $(function() { $('#get-code-btn').click(function() { var email = $('#email').val(); $.ajax({ url: '/admin/', method: 'POST', data: {email: email}, success: function(data) { if (data.status == 'success') { // 获取验证码成功,开始倒计时 var count = 60; var timer = setInterval(function() { if (count == 0) { clearInterval(timer); $('#get-code-btn').prop('disabled', false).text('获取验证码'); } else { $('#get-code-btn').prop('disabled', true).text(count + '秒后重试'); count--; } }, 1000); } else { alert('获取验证码失败,请重试!'); } }, error: function() { alert('获取验证码失败,请重试!'); } }); }); $('#login-form').submit(function() { var email = $('#email').val(); var code = $('#code').val(); $.ajax({ url: '/response/', method: 'POST', data: {email: email, code: code}, success: function(data) { if (data.status == 'success') { // 验证码校验成功,跳转到目标页面 window.location.href = 'http://spacexs.cn'; } else { alert('验证码错误,请重新输入!'); } }, error: function() { alert('验证码错误,请重试!'); } }); return false; }); }); </script> </body> </html>
时间: 2023-12-06 19:40:50 浏览: 111
<!DOCTYPE html>
<html>
<head>
<meta lang="zn">
<meta charset="utf-8">
<title>文件实验室账号登录</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
font-family: 楷体;
font-size: 1.2rem;
padding: 1rem;
}
form {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
max-width: 400px;
margin: auto;
}
label {
margin-bottom: 0.5rem;
}
input[type='email'], input[type='text'] {
padding: 0.5rem;
margin-bottom: 1rem;
border: none;
border-bottom: 2px solid #ddd;
width: 100%;
box-sizing: border-box;
font-size: 1.2rem;
}
button {
padding: 0.5rem;
border: none;
background-color: #007bff;
color: #fff;
font-size: 1.2rem;
cursor: pointer;
}
button:hover {
background-color: #0069d9;
}
button:disabled {
background-color: #ddd;
color: #333;
cursor: not-allowed;
}
</style>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
</head>
<body>
<form id="login-form" action="#">
<label for="email">邮箱账号:</label>
<input type="email" id="email" name="email" placeholder="在此输入邮箱账号">
<button type="button" id="get-code-btn">获取验证码</button>
<label for="code">验证码:</label>
<input type="text" id="code" name="code" placeholder="在此输入收到的验证码">
<button type="submit">登录</button>
</form>
<script>
$(function() {
$('#get-code-btn').click(function() {
var email = $('#email').val();
$.ajax({
url: '/admin/',
method: 'POST',
data: {email: email},
success: function(data) {
if (data.status == 'success') {
// 获取验证码成功,开始倒计时
var count = 60;
var timer = setInterval(function() {
if (count == 0) {
clearInterval(timer);
$('#get-code-btn').prop('disabled', false).text('获取验证码');
} else {
$('#get-code-btn').prop('disabled', true).text(count + '秒后重试');
count--;
}
}, 1000);
} else {
alert('获取验证码失败,请重试!');
}
},
error: function() {
alert('获取验证码失败,请重试!');
}
});
});
$('#login-form').submit(function() {
var email = $('#email').val();
var code = $('#code').val();
$.ajax({
url: '/response/',
method: 'POST',
data: {email: email, code: code},
success: function(data) {
if (data.status == 'success') {
// 验证码校验成功,跳转到目标页面
window.location.href = 'http://spacexs.cn';
} else {
alert('验证码错误,请重新输入!');
}
},
error: function() {
alert('验证码错误,请重试!');
}
});
return false;
});
});
</script>
</body>
</html>
阅读全文