66 lines
1.7 KiB
HTML
66 lines
1.7 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>详情页</title>
|
|
<style>
|
|
.photo img{
|
|
/* width: 100px; */
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="photo">
|
|
|
|
</div>
|
|
</body>
|
|
<script>
|
|
//调用接口
|
|
function getData() {
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open("GET", `http://127.0.0.1:3000/api/json/info?id=${total("id")}&quantity=${total("total")}`)
|
|
xhr.send()
|
|
xhr.onreadystatechange = () => {
|
|
if (xhr.readyState == 4) {
|
|
if (xhr.status == 200) {
|
|
//data 字符串类型的对象或数组传
|
|
var data = JSON.parse(xhr.response)//从response中取数据
|
|
rendList(data)
|
|
}
|
|
} else {
|
|
alert("当前网络不佳,请稍后重试!")
|
|
}
|
|
}
|
|
}
|
|
getData()
|
|
|
|
//渲染页面
|
|
function rendList(list) {
|
|
console.log("详情页数据:",list);
|
|
list.result.forEach(v => {
|
|
$(".photo").innerHTML +=`
|
|
<img src="${v}" alt="">
|
|
`
|
|
})
|
|
}
|
|
//地址栏取参数
|
|
function total(name) {
|
|
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
|
|
var r = window.location.search.substr(1).match(reg);
|
|
if (r != null) return unescape(r[2]); return null;
|
|
}
|
|
//console.log("a",total("id"));
|
|
|
|
function $(className) {
|
|
return document.querySelector(className);
|
|
}
|
|
function _(className) {
|
|
return document.querySelectorAll(className);
|
|
}
|
|
</script>
|
|
|
|
</html> |