我想制作一个页面,显示Mars Insight中的所有图像。 我如何使其重复自身,以便其生成带有新图像的更多iframe?图像文件编号为12,依此类推,目前仅显示1张图像。
var insightFeed = {
url: "https://mars.nasa.gov/raw_images/embed/",
file: 12,
showImage: function() {
window.onload = function() {
var iframe = document.createElement('iframe');
iframe.style.display = "block";
iframe.style.height = "420px";
iframe.style.width = "400px";
iframe.style.border = "none";
iframe.src = insightFeed.url + (insightFeed.file);
document.body.appendChild(iframe);
}
}
};
insightFeed.showImage();
答案 0 :(得分:0)
由于数字不是连续的(例如1到20),因此您必须将其打孔。我重新编写了代码,以便您可以这样做:
var insightFeed = {
url: "https://mars.nasa.gov/raw_images/embed/",
showImage: function(image) {
var iframe = document.createElement('iframe');
iframe.style.display = "block";
iframe.style.height = "420px";
iframe.style.width = "400px";
iframe.style.border = "none";
iframe.src = insightFeed.url + (image);
document.body.appendChild(iframe);
}
};
window.onload = function() {
insightFeed.showImage(12);
insightFeed.showImage(13);
insightFeed.showImage(14);
}