帮我写一个html页面: 页面是左右布局,输入框按钮等靠右边; 页面需要自适应,能够适应pc页面手机页面; 标签名称为文件实验室/账号登录; 两个input框,一个显示输入接收验证码的邮箱在他的右边有一个按钮名称为获取验证码, 第二个input输入框显示输入验证码,他的下方是一个登录按钮; 然后使用ajax技术,将获取到的邮箱账号使用post发送到/admin/等待后端发送验证码,获取验证码的按钮点击后显示60秒后再试期间按钮不能触发; 用户填入验证码后使用post发送到/response/等待后端验证,后端验证通过后跳转到https://www.spacexs.cn,失败则要求重新输入; 字体使用楷体,页面语言是简体中文, 要求点击获取验证码后,按钮文本显示为60秒后再试期间禁用按钮 使用ajax发送请求
时间: 2023-12-06 20:39:53 浏览: 51
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>文件实验室/账号登录</title>
<style>
body {
font-family: "楷体", "KaiTi", STKaiti, "华文楷体", serif;
}
.container {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 20px;
}
.input-container {
display: flex;
flex-direction: row;
align-items: center;
}
input[type="text"],
input[type="password"] {
padding: 10px;
margin-right: 10px;
}
.button-container button {
padding: 10px;
font-size: 16px;
}
</style>
</head>
<body>
<div class="container">
<h1>文件实验室/账号登录</h1>
<div class="input-container">
<input type="text" placeholder="输入接收验证码的邮箱" id="email" />
<div class="button-container">
<button id="getCode">获取验证码</button>
</div>
</div>
<div class="input-container">
<input type="text" placeholder="输入验证码" id="verifyCode" />
</div>
<div class="button-container">
<button id="login">登录</button>
</div>
</div>
<script>
// 获取验证码按钮点击事件
const getCodeBtn = document.querySelector("#getCode");
getCodeBtn.addEventListener("click", () => {
// 禁用按钮
getCodeBtn.disabled = true;
getCodeBtn.innerText = "60秒后再试";
let countDown = 60;
const intervalId = setInterval(() => {
countDown--;
getCodeBtn.innerText = `${countDown}秒后再试`;
if (countDown === 0) {
clearInterval(intervalId);
getCodeBtn.disabled = false;
getCodeBtn.innerText = "获取验证码";
}
}, 1000);
// 发送请求
const email = document.querySelector("#email").value;
const xhr = new XMLHttpRequest();
xhr.open("POST", "/admin/");
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
console.log(xhr.responseText);
}
};
xhr.send(JSON.stringify({ email }));
});
// 登录按钮点击事件
const loginBtn = document.querySelector("#login");
loginBtn.addEventListener("click", () => {
const verifyCode = document.querySelector("#verifyCode").value;
const xhr = new XMLHttpRequest();
xhr.open("POST", "/response/");
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
const response = JSON.parse(xhr.responseText);
if (response.success) {
window.location.href = "https://www.spacexs.cn";
} else {
alert(response.message);
}
}
};
xhr.send(JSON.stringify({ verifyCode }));
});
</script>
</body>
</html>
阅读全文