所以,如果我想在網上抓取幾張圖片,將它們放入一個數組中並在網站上使用它們,我正在使用Javascript怎麼做。HTML5中的圖像數組
var images = [
{caption: "Red Slate Mountain", alt: "Mountain", url:"https://upload.wikimedia.org/wikipedia/commons/thumb/2/20/Red_Slate_Mountain_1.jpg/320px-Red_Slate_Mountain_1.jpg"},
{caption: "St. Petersburg River", alt: "River", url: "https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Saint-petersburg-river-march-24-2016.jpg/320px-Saint-petersburg-river-march-24-2016.jpg"},
{caption: "Lybian Desert", alt: "Desert", url: "https://upload.wikimedia.org/wikipedia/commons/thumb/9/99/Libyan_Desert_-_2006.jpg/320px-Libyan_Desert_-_2006.jpg"},
{caption: "Azerbaijan Forest", alt: "Forest", url: "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6d/Azerbaijan_forest_3.JPG/320px-Azerbaijan_forest_3.JPG"},
{caption: "Indonesian Jungle", alt: "Jungle", url: "https://upload.wikimedia.org/wikipedia/commons/thumb/f/f5/Indonesian_jungle3%2C_Zoo_Prague.jpg/320px-Indonesian_jungle3%2C_Zoo_Prague.jpg"}
];
這些都是一些圖片,我有一個標題有畫面下,中高音如果它不加載圖片,以及位置的URL。
容器我至今是:
window.onload = function(){
var imageContainer = document.querySelector("#image");
for(var i=0; i < images.length; i++){
var myImageStr += "<img alt='" + images[i].alt + "'" +
" src='" + images[i].url + "' />";
imageContainer.innerHTML = myImageStr;
};
這不加載任何東西,所以我假定我的東西我在這裏下車,只是不知道是什麼。任何幫助請:)
是否有瀏覽器控制檯的任何消息? – NineBerry
不,只是一個標題說「圖像陣列」 –