Files
ClassContent/历届学生/front-end-team-10/每天课程/2023-03-03/info.html
2024-09-27 02:06:13 +08:00

71 lines
1.6 KiB
HTML

<!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>Document</title>
<style>
img {
width: 100px;
}
</style>
</head>
<body>
<div class="img">
</div>
</body>
<script>
function getData() {
var xhr = new XMLHttpRequest();
xhr.open("GET", `http://127.0.0.1:3000/api/json/info?id=${query("id")}&quantity=${query("sl")}`)
xhr.send()
xhr.onreadystatechange = () => {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var data = JSON.parse(xhr.response);
rendList(data)
} else {
alert("当前网络不佳,请稍后再试!")
}
}
}
}
function rendList(list) {
console.log("详情:", list);
list.result.forEach(v => {
$(".img").innerHTML += `
<img src="${v}" alt="">
`
});
}
getData()
function query(name) {
let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
let r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
};
return null;
}
function $(className) {
return document.querySelector(className)
}
function _(className) {
return document.querySelectorAll(className)
}
</script>
</html>