<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>promise封装</title>
<script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
</head>
<style>
body {
background-image: url("https://static.runoob.com/images/mix/gradient2.png");
background-repeat: repeat-x;
}
#box {
width: 320px;
height: 320px;
margin: auto;
margin-top: 10%;
background: #fff;
border: 2px solid rgba(183, 203, 225, 0.523);
}
.inp {
width: 250px;
height: 29px;
margin-top: 20px;
margin-left: 30px;
border: 1px solid #ddd;
}
.nnb {
width: 179px;
height: 29px;
margin-top: 20px;
margin-left: 30px;
border: 1px solid #ddd;
}
.nnc {
width: 70px;
height: 33px;
position: absolute;
margin-top: 20px;
border: 1px solid #ddd;
background-color: #fff;
}
.che {
margin-left: 30px;
margin-top: 20px;
}
#login {
width: 260px;
height: 35px;
color: #fff;
margin-top: 15px;
margin-left: 30px;
border: 1px solid #fff;
background: #409eff;
}
div {
width: 260px;
height: 25px;
border: 1px solid #fff;
margin-left: 30px;
margin-top: 20px;
}
span {
font-size: 13px;
position: absolute;
margin-top: 17px;
}
</style>
<body>
<div id="box">
<div>账号登录</div>
<input type="text" class="inp" placeholder="用户名" id="username" />
<input type="text" class="inp" placeholder="密码" id="password" />
<input type="text" class="nnb" placeholder="验证码" id="vercode" />
<button class="nnc"></button>
<br />
<input type="checkbox" class="che" /><span>记住密码</span>
<button id="login">登 录</button>
</div>
</body>
<script type="module">
$(function () {
// 输入框默认值
$("#username").val("11");
$("#password").val("22");
$("#login").click(function(){
location.href = "././3.1网页.html";
})
});
// 懒加载封装
// 登录
import { postlogin, getCode } from "./Flogin.js";
postlogin().then((res) => {
console.log(res);
});
// 验证码
getCode().then((res) => {
console.log(res);
});
</script>
</html>
Flogin.js文件
// 懒加载封装
// 登录
export function postlogin() {
return new Promise((resolve, reject) => {
$.ajax({
url: "http://47.94.4.201/index.php/index/index/login",
type: "POST",
dataType: "json",
data: {
username: $("username").val(),
password: $("password").val(),
vercode: $("vercode").val(),
},
success: function (data) {
console.log(data);
},
});
});
}
// 验证码
export function getCode() {
return new Promise((resolve, reject) => {
$.ajax({
url: "http://47.94.4.201/index.php/index/index/getcode",
type: "GET",
dataType: "json",
success: function (data) {
console.log(data);
$(".nnc").html(data.msg);
},
});
$(".nnc").click(function () {
getCode();
});
});
}