换一换
var page = 1;
document.querySelector("#btn").addEventListener('click', function() {
page++;
document.querySelector("#list").innerHTML = ""
loadXMLDoc();
})
function loadXMLDoc() {
var xmlhttp;
if(window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
}
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var json = xmlhttp.responseText;
json = JSON.parse(json)
for(let i = 0; i < json.shop.length; i++) {
var img = document.createElement('img');
img.src = json.shop[i].pic;
var h3 = document.createElement('h3');
h3.innerHTML = json.shop[i].title;
var p = document.createElement('p');
p.innerHTML = json.shop[i].price
var div = document.createElement('div');
div.appendChild(img)
div.appendChild(h3)
div.appendChild(p)
console.log(div);
document.querySelector("#list").appendChild(div)
}
}
}
xmlhttp.open("GET", page + ".json", true);
xmlhttp.send();
}
loadXMLDoc();
一键复制
编辑
Web IDE
原始数据
按行查看
历史